mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-01 01:19:59 +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)
|
return usersDao.saveUser(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun setUserAsActiveWithId(id: Long) {
|
override suspend fun setUserAsActiveWithId(id: Long): Boolean {
|
||||||
usersDao.setUserAsActiveWithId(id)
|
return usersDao.setUserAsActiveWithId(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun deleteUserWithId(id: Long) {
|
override suspend fun deleteUserWithId(id: Long) {
|
||||||
|
@ -35,7 +35,7 @@ interface UsersRepository {
|
|||||||
suspend fun getUserWithUsernameAndServer(username: String, server: String): UserNgEntity?
|
suspend fun getUserWithUsernameAndServer(username: String, server: String): UserNgEntity?
|
||||||
suspend fun updateUser(user: UserNgEntity): Int
|
suspend fun updateUser(user: UserNgEntity): Int
|
||||||
suspend fun insertUser(user: UserNgEntity): Long
|
suspend fun insertUser(user: UserNgEntity): Long
|
||||||
suspend fun setUserAsActiveWithId(id: Long)
|
suspend fun setUserAsActiveWithId(id: Long): Boolean
|
||||||
suspend fun deleteUserWithId(id: Long)
|
suspend fun deleteUserWithId(id: Long)
|
||||||
suspend fun setAnyUserAsActive(): Boolean
|
suspend fun setAnyUserAsActive(): Boolean
|
||||||
suspend fun markUserForDeletion(id: Long): Boolean
|
suspend fun markUserForDeletion(id: Long): Boolean
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
package com.nextcloud.talk.newarch.features.settingsflow.settings
|
package com.nextcloud.talk.newarch.features.settingsflow.settings
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import com.nextcloud.talk.newarch.data.source.remote.ApiErrorHandler
|
import com.nextcloud.talk.newarch.data.source.remote.ApiErrorHandler
|
||||||
import com.nextcloud.talk.newarch.domain.repository.offline.UsersRepository
|
import com.nextcloud.talk.newarch.domain.repository.offline.UsersRepository
|
||||||
import com.nextcloud.talk.newarch.local.models.User
|
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.services.GlobalService
|
||||||
import com.nextcloud.talk.newarch.utils.NetworkComponents
|
import com.nextcloud.talk.newarch.utils.NetworkComponents
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@ -45,21 +43,19 @@ class SettingsViewModel constructor(
|
|||||||
val users = usersRepository.getUsersLiveData()
|
val users = usersRepository.getUsersLiveData()
|
||||||
val activeUser = globalService.currentUserLiveData
|
val activeUser = globalService.currentUserLiveData
|
||||||
|
|
||||||
fun setUserAsActive(user: User): Boolean {
|
private suspend fun setUserAsActiveWithId(id: Long): Boolean {
|
||||||
if (user.status == UserStatus.DORMANT) {
|
return usersRepository.setUserAsActiveWithId(id)
|
||||||
val job = runBlocking {
|
}
|
||||||
viewModelScope.launch {
|
|
||||||
user.id?.let {
|
|
||||||
usersRepository.setUserAsActiveWithId(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
job.start()
|
fun setUserAsActive(user: User): Boolean = runBlocking {
|
||||||
return true
|
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 {
|
private suspend fun removeUserWithId(id: Long): Boolean {
|
||||||
|
@ -65,7 +65,7 @@ abstract class UsersDao {
|
|||||||
abstract suspend fun getUserWithUsernameAndServer(username: String, server: String): UserNgEntity?
|
abstract suspend fun getUserWithUsernameAndServer(username: String, server: String): UserNgEntity?
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
open suspend fun setUserAsActiveWithId(id: Long) {
|
open suspend fun setUserAsActiveWithId(id: Long) : Boolean {
|
||||||
val users = getUsers()
|
val users = getUsers()
|
||||||
for (user in users) {
|
for (user in users) {
|
||||||
if (user.id != id && UserStatus.ACTIVE == user.status) {
|
if (user.id != id && UserStatus.ACTIVE == user.status) {
|
||||||
@ -76,6 +76,8 @@ abstract class UsersDao {
|
|||||||
updateUser(user)
|
updateUser(user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
|
Loading…
Reference in New Issue
Block a user