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

View file

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