Skip to content

Commit

Permalink
Merge pull request #4667 from nextcloud/bugfix/4492/fixMissingUsersInUI
Browse files Browse the repository at this point in the history
Bugfix/4492/fix missing users in UI
  • Loading branch information
rapterjet2004 authored Feb 3, 2025
2 parents a098de9 + b69f215 commit 3d2f999
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package com.nextcloud.talk.data.user

import android.util.Log
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.json.push.PushConfigurationState
import io.reactivex.Maybe
Expand All @@ -17,7 +18,12 @@ import io.reactivex.Single
class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {

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> {
Expand Down Expand Up @@ -62,6 +68,7 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {

override fun setUserAsActiveWithId(id: Long): Single<Boolean> {
val amountUpdated = usersDao.setUserAsActiveWithId(id)
Log.d(TAG, "setUserAsActiveWithId. amountUpdated: $amountUpdated")
return if (amountUpdated > 0) {
Single.just(true)
} else {
Expand All @@ -76,4 +83,8 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
override fun updatePushState(id: Long, state: PushConfigurationState): Single<Int> {
return usersDao.updatePushState(id, state)
}

companion object {
private val TAG = UsersRepositoryImpl::class.simpleName
}
}
13 changes: 7 additions & 6 deletions app/src/main/java/com/nextcloud/talk/users/UserManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.nextcloud.talk.users

import android.text.TextUtils
import android.util.Log
import com.bluelinelabs.logansquare.LoganSquare
import com.nextcloud.talk.data.user.UsersRepository
import com.nextcloud.talk.data.user.model.User
Expand All @@ -30,7 +31,7 @@ class UserManager internal constructor(private val userRepository: UsersReposito
val currentUser: Maybe<User>
get() {
return userRepository.getActiveUser()
.switchIfEmpty(getAnyUserAndSetAsActive())
.switchIfEmpty(Maybe.defer { getAnyUserAndSetAsActive() })
}

val currentUserObservable: Observable<User>
Expand Down Expand Up @@ -88,12 +89,11 @@ class UserManager internal constructor(private val userRepository: UsersReposito
.flatMapMaybe {
if (it.isNotEmpty()) {
val user = it.first()
user.apply {
current = true
}.also { currentUser ->
userRepository.updateUser(currentUser)
if (setUserAsActive(user).blockingGet()) {
userRepository.getActiveUser()
} else {
Maybe.empty()
}
Maybe.just(user)
} else {
Maybe.empty()
}
Expand Down Expand Up @@ -123,6 +123,7 @@ class UserManager internal constructor(private val userRepository: UsersReposito
}

fun setUserAsActive(user: User): Single<Boolean> {
Log.d(TAG, "setUserAsActive:" + user.id!!)
return userRepository.setUserAsActiveWithId(user.id!!)
}

Expand Down

0 comments on commit 3d2f999

Please sign in to comment.