8000 Bugfix/4492/fix missing users in UI by mahibi · Pull Request #4667 · nextcloud/talk-android · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Bugfix/4492/fix missing users in UI #4667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
0