mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-30 17:10:31 +01:00
Work on switching accounts
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
7b8f518099
commit
82fa6fa301
@ -71,8 +71,8 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
|
||||
return usersDao.saveUser(user)
|
||||
}
|
||||
|
||||
override suspend fun setUserAsActiveWithId(id: Long) {
|
||||
usersDao.setUserAsActiveWithId(id)
|
||||
override suspend fun setUserAsActiveWithId(id: Long): Boolean {
|
||||
return usersDao.setUserAsActiveWithId(id)
|
||||
}
|
||||
|
||||
override suspend fun deleteUserWithId(id: Long) {
|
||||
|
@ -35,7 +35,7 @@ interface UsersRepository {
|
||||
suspend fun getUserWithUsernameAndServer(username: String, server: String): UserNgEntity?
|
||||
suspend fun updateUser(user: UserNgEntity): Int
|
||||
suspend fun insertUser(user: UserNgEntity): Long
|
||||
suspend fun setUserAsActiveWithId(id: Long)
|
||||
suspend fun setUserAsActiveWithId(id: Long): Boolean
|
||||
suspend fun deleteUserWithId(id: Long)
|
||||
suspend fun setAnyUserAsActive(): Boolean
|
||||
suspend fun markUserForDeletion(id: Long): Boolean
|
||||
|
@ -22,7 +22,6 @@
|
||||
package com.nextcloud.talk.newarch.features.settingsflow.settings
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.nextcloud.talk.newarch.data.source.remote.ApiErrorHandler
|
||||
import com.nextcloud.talk.newarch.domain.repository.offline.UsersRepository
|
||||
import com.nextcloud.talk.newarch.local.models.User
|
||||
@ -31,7 +30,6 @@ import com.nextcloud.talk.newarch.mvvm.BaseViewModel
|
||||
import com.nextcloud.talk.newarch.services.GlobalService
|
||||
import com.nextcloud.talk.newarch.utils.NetworkComponents
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@ -45,21 +43,19 @@ class SettingsViewModel constructor(
|
||||
val users = usersRepository.getUsersLiveData()
|
||||
val activeUser = globalService.currentUserLiveData
|
||||
|
||||
fun setUserAsActive(user: User): Boolean {
|
||||
if (user.status == UserStatus.DORMANT) {
|
||||
val job = runBlocking {
|
||||
viewModelScope.launch {
|
||||
user.id?.let {
|
||||
usersRepository.setUserAsActiveWithId(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
private suspend fun setUserAsActiveWithId(id: Long): Boolean {
|
||||
return usersRepository.setUserAsActiveWithId(id)
|
||||
}
|
||||
|
||||
job.start()
|
||||
return true
|
||||
fun setUserAsActive(user: User): Boolean = runBlocking {
|
||||
var operationFinished = false
|
||||
if (user.status == UserStatus.DORMANT) {
|
||||
operationFinished = withContext(Dispatchers.Default) {
|
||||
runBlocking { setUserAsActive(user) }
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
operationFinished
|
||||
}
|
||||
|
||||
private suspend fun removeUserWithId(id: Long): Boolean {
|
||||
|
@ -65,7 +65,7 @@ abstract class UsersDao {
|
||||
abstract suspend fun getUserWithUsernameAndServer(username: String, server: String): UserNgEntity?
|
||||
|
||||
@Transaction
|
||||
open suspend fun setUserAsActiveWithId(id: Long) {
|
||||
open suspend fun setUserAsActiveWithId(id: Long) : Boolean {
|
||||
val users = getUsers()
|
||||
for (user in users) {
|
||||
if (user.id != id && UserStatus.ACTIVE == user.status) {
|
||||
@ -76,6 +76,8 @@ abstract class UsersDao {
|
||||
updateUser(user)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@Transaction
|
||||
|
Loading…
Reference in New Issue
Block a user