mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
PushUtils: update only pushState when updating users
This is to work around a race condition where this class would asynchronously overwrite other user attributes with old values after a user switch. Co-authored-by: Marcel Hibbe <dev@mhibbe.de> Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
2e2d4a9ca3
commit
a37f947eb9
@ -29,6 +29,7 @@ import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.nextcloud.talk.data.user.model.UserEntity
|
||||
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
@ -89,6 +90,9 @@ abstract class UsersDao {
|
||||
)
|
||||
abstract fun setUserAsActiveWithId(id: Long): Int
|
||||
|
||||
@Query("Update User SET pushConfigurationState = :state WHERE id == :id")
|
||||
abstract fun updatePushState(id: Long, state: PushConfigurationState): Single<Int>
|
||||
|
||||
companion object {
|
||||
const val TAG = "UsersDao"
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package com.nextcloud.talk.data.user
|
||||
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
@ -42,4 +43,5 @@ interface UsersRepository {
|
||||
fun insertUser(user: User): Long
|
||||
fun setUserAsActiveWithId(id: Long): Single<Boolean>
|
||||
fun deleteUser(user: User): Int
|
||||
fun updatePushState(id: Long, state: PushConfigurationState): Single<Int>
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
package com.nextcloud.talk.data.user
|
||||
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
||||
import io.reactivex.Maybe
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
@ -86,4 +87,8 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
|
||||
override fun deleteUser(user: User): Int {
|
||||
return usersDao.deleteUser(UserMapper.toEntity(user))
|
||||
}
|
||||
|
||||
override fun updatePushState(id: Long, state: PushConfigurationState): Single<Int> {
|
||||
return usersDao.updatePushState(id, state)
|
||||
}
|
||||
}
|
||||
|
@ -230,6 +230,10 @@ class UserManager internal constructor(private val userRepository: UsersReposito
|
||||
return user
|
||||
}
|
||||
|
||||
fun updatePushState(id: Long, state: PushConfigurationState): Single<Int> {
|
||||
return userRepository.updatePushState(id, state)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "UserManager"
|
||||
}
|
||||
|
@ -338,8 +338,7 @@ public class PushUtils {
|
||||
pushConfigurationState.setUserPublicKey(proxyMap.get("userPublicKey"));
|
||||
pushConfigurationState.setUsesRegularPass(Boolean.FALSE);
|
||||
|
||||
user.setPushConfigurationState(pushConfigurationState);
|
||||
userManager.saveUser(user).subscribe(new SingleObserver<Integer>() {
|
||||
userManager.updatePushState(user.getId(), pushConfigurationState).subscribe(new SingleObserver<Integer>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
// unused atm
|
||||
|
Loading…
Reference in New Issue
Block a user