UsersDao: make setUserAsActiveWithId blocking

Room won't accept non-blocking @Transactions, which makes sense

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-06-30 17:12:26 +02:00 committed by Andy Scherzinger
parent 0ac26f557b
commit 886a3d0df2
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
2 changed files with 12 additions and 13 deletions

View file

@ -83,16 +83,15 @@ abstract class UsersDao {
abstract fun getUserWithUsernameAndServer(username: String, server: String): Maybe<UserEntity>
@Transaction
open fun setUserAsActiveWithId(id: Long): Single<Boolean> {
return getUsers()
.map { users ->
users.forEach { user ->
@Suppress("Detekt.TooGenericExceptionCaught") // blockingGet() only throws RuntimeExceptions per rx docs
open fun setUserAsActiveWithId(id: Long): Boolean {
return try {
getUsers().blockingGet().forEach { user ->
user.current = user.id == id
updateUser(user)
}
true
}
.onErrorReturn { e ->
} catch (e: RuntimeException) {
Log.e(TAG, "Error setting user active", e)
false
}

View file

@ -74,7 +74,7 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
}
override fun setUserAsActiveWithId(id: Long): Single<Boolean> {
return usersDao.setUserAsActiveWithId(id)
return Single.just(usersDao.setUserAsActiveWithId(id))
}
override fun deleteUserWithId(id: Long) {