mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
self heal if multiple current users exist
usersDao.getActiveUser() will return only one current users even if multiple exist for whatever reason. By executing setUserAsActiveWithId(it.id) with the same user, it is made sure all other users current status is set to 0. This change won't fix the root cause if multiple users are set to current, but it will make sure the state is fixed as soon as there is a query to get the active user. In fact, this change might also make it harder to find the root cause because debugging may be more difficult! When searching for the root cause, always keep this in mind and maybe revert the change. Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
22b8b59fb3
commit
b69f21580a
@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.nextcloud.talk.data.user
|
package com.nextcloud.talk.data.user
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
||||||
import io.reactivex.Maybe
|
import io.reactivex.Maybe
|
||||||
@ -17,7 +18,12 @@ import io.reactivex.Single
|
|||||||
class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
|
class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
|
||||||
|
|
||||||
override fun getActiveUser(): Maybe<User> {
|
override fun getActiveUser(): Maybe<User> {
|
||||||
return usersDao.getActiveUser().map { UserMapper.toModel(it) }
|
val user = usersDao.getActiveUser()
|
||||||
|
.map {
|
||||||
|
setUserAsActiveWithId(it.id)
|
||||||
|
UserMapper.toModel(it)!!
|
||||||
|
}
|
||||||
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getActiveUserObservable(): Observable<User> {
|
override fun getActiveUserObservable(): Observable<User> {
|
||||||
@ -62,6 +68,7 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
|
|||||||
|
|
||||||
override fun setUserAsActiveWithId(id: Long): Single<Boolean> {
|
override fun setUserAsActiveWithId(id: Long): Single<Boolean> {
|
||||||
val amountUpdated = usersDao.setUserAsActiveWithId(id)
|
val amountUpdated = usersDao.setUserAsActiveWithId(id)
|
||||||
|
Log.d(TAG, "setUserAsActiveWithId. amountUpdated: $amountUpdated")
|
||||||
return if (amountUpdated > 0) {
|
return if (amountUpdated > 0) {
|
||||||
Single.just(true)
|
Single.just(true)
|
||||||
} else {
|
} else {
|
||||||
@ -76,4 +83,8 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
|
|||||||
override fun updatePushState(id: Long, state: PushConfigurationState): Single<Int> {
|
override fun updatePushState(id: Long, state: PushConfigurationState): Single<Int> {
|
||||||
return usersDao.updatePushState(id, state)
|
return usersDao.updatePushState(id, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = UsersRepositoryImpl::class.simpleName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user