use setUserAsActive instead of userManager.disableAllUsersWithoutId

just refactoring for now. this doesn't solve the bug!

Problem that needs to be solved:
When adding a new Account (User), it is marked as "current", while for the other logged in users "current" must be unset (-> disabled).

The problem is, that for the old active user, "current" is not unset so there were multiple accounts marked as "current".

In the ChooseAccountDialogFragment, only one of the current accounts is shown at the top. Below the set status field, all accounts are listed that are not marked with "current". So as a result, there can be accounts hidden that were marked as "current".

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-11-18 14:56:31 +01:00 committed by Andy Scherzinger
parent 82b4907118
commit d4e545e67d
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
6 changed files with 36 additions and 39 deletions

View File

@ -28,6 +28,7 @@ import android.os.Handler
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.Toast
import androidx.work.Data import androidx.work.Data
import androidx.work.OneTimeWorkRequest import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager import androidx.work.WorkManager
@ -443,25 +444,33 @@ class AccountVerificationController(args: Bundle? = null) :
} }
private fun proceedWithLogin() { private fun proceedWithLogin() {
Log.d(TAG, "proceedWithLogin...")
cookieManager.cookieStore.removeAll() cookieManager.cookieStore.removeAll()
val userDisabledCount = userManager.disableAllUsersWithoutId(internalAccountId).blockingGet()
Log.d(TAG, "Disabled $userDisabledCount users that had no id") val userToSetAsActive = userManager.getUserWithId(internalAccountId).blockingGet()
if (activity != null) { Log.d(TAG, "userToSetAsActive: " + userToSetAsActive.username)
activity!!.runOnUiThread {
if (userManager.users.blockingGet().size == 1) { if (userManager.setUserAsActive(userToSetAsActive).blockingGet()) {
router.setRoot( if (activity != null) {
RouterTransaction.with(ConversationsListController(Bundle())) activity!!.runOnUiThread {
.pushChangeHandler(HorizontalChangeHandler()) if (userManager.users.blockingGet().size == 1) {
.popChangeHandler(HorizontalChangeHandler()) router.setRoot(
) RouterTransaction.with(ConversationsListController(Bundle()))
} else { .pushChangeHandler(HorizontalChangeHandler())
if (isAccountImport) { .popChangeHandler(HorizontalChangeHandler())
ApplicationWideMessageHolder.getInstance().messageType = )
ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED } else {
if (isAccountImport) {
ApplicationWideMessageHolder.getInstance().messageType =
ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED
}
router.popToRoot()
} }
router.popToRoot()
} }
} }
} else {
Log.e(TAG, "failed to set active user")
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
} }
} }

View File

@ -74,9 +74,6 @@ abstract class UsersDao {
@Query("SELECT * FROM User where userId = :userId") @Query("SELECT * FROM User where userId = :userId")
abstract fun getUserWithUserId(userId: String): Maybe<UserEntity> abstract fun getUserWithUserId(userId: String): Maybe<UserEntity>
@Query("SELECT * FROM User where id != :id")
abstract fun getUsersWithoutId(id: Long): Single<List<UserEntity>>
@Query("SELECT * FROM User where scheduledForDeletion = 1") @Query("SELECT * FROM User where scheduledForDeletion = 1")
abstract fun getUsersScheduledForDeletion(): Single<List<UserEntity>> abstract fun getUsersScheduledForDeletion(): Single<List<UserEntity>>
@ -92,6 +89,13 @@ abstract class UsersDao {
return try { return try {
getUsers().blockingGet().forEach { user -> getUsers().blockingGet().forEach { user ->
user.current = user.id == id user.current = user.id == id
Log.d(TAG, "xxxxxxxxxxxx")
Log.d(TAG, "setUserAsActiveWithId. user.username: " + user.username)
Log.d(TAG, "setUserAsActiveWithId. user.id: " + user.id)
Log.d(TAG, "setUserAsActiveWithId. user.current: " + user.current)
Log.d(TAG, "xxxxxxxxxxxx")
updateUser(user) updateUser(user)
} }
true true

View File

@ -35,7 +35,6 @@ interface UsersRepository {
fun getUserWithId(id: Long): Maybe<User> fun getUserWithId(id: Long): Maybe<User>
fun getUserWithIdNotScheduledForDeletion(id: Long): Maybe<User> fun getUserWithIdNotScheduledForDeletion(id: Long): Maybe<User>
fun getUserWithUserId(userId: String): Maybe<User> fun getUserWithUserId(userId: String): Maybe<User>
fun getUsersWithoutUserId(id: Long): Single<List<User>>
fun getUsersScheduledForDeletion(): Single<List<User>> fun getUsersScheduledForDeletion(): Single<List<User>>
fun getUsersNotScheduledForDeletion(): Single<List<User>> fun getUsersNotScheduledForDeletion(): Single<List<User>>
fun getUserWithUsernameAndServer(username: String, server: String): Maybe<User> fun getUserWithUsernameAndServer(username: String, server: String): Maybe<User>

View File

@ -54,10 +54,6 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
return usersDao.getUserWithUserId(userId).map { UserMapper.toModel(it) } return usersDao.getUserWithUserId(userId).map { UserMapper.toModel(it) }
} }
override fun getUsersWithoutUserId(id: Long): Single<List<User>> {
return usersDao.getUsersWithoutId(id).map { UserMapper.toModel(it) }
}
override fun getUsersScheduledForDeletion(): Single<List<User>> { override fun getUsersScheduledForDeletion(): Single<List<User>> {
return usersDao.getUsersScheduledForDeletion().map { UserMapper.toModel(it) } return usersDao.getUsersScheduledForDeletion().map { UserMapper.toModel(it) }
} }

View File

@ -148,6 +148,11 @@ public class ChooseAccountDialogFragment extends DialogFragment {
for (Object userItem : userManager.getUsers().blockingGet()) { for (Object userItem : userManager.getUsers().blockingGet()) {
userEntity = (User) userItem; userEntity = (User) userItem;
Log.d(TAG, "---------------------");
Log.d(TAG, "userEntity.getUserId() " + userEntity.getUserId());
Log.d(TAG, "userEntity.getCurrent() " + userEntity.getCurrent());
Log.d(TAG, "---------------------");
if (!userEntity.getCurrent()) { if (!userEntity.getCurrent()) {
String userId; String userId;
if (userEntity.getUserId() != null) { if (userEntity.getUserId() != null) {

View File

@ -58,22 +58,6 @@ class UserManager internal constructor(private val userRepository: UsersReposito
return userRepository.getUserWithId(id) return userRepository.getUserWithId(id)
} }
fun disableAllUsersWithoutId(id: Long): Single<Int> {
val results = userRepository.getUsersWithoutUserId(id)
return results.map { users ->
var count = 0
if (users.isNotEmpty()) {
for (entity in users) {
entity.current = false
userRepository.updateUser(entity)
count++
}
}
count
}
}
fun checkIfUserIsScheduledForDeletion(username: String, server: String): Single<Boolean> { fun checkIfUserIsScheduledForDeletion(username: String, server: String): Single<Boolean> {
return userRepository return userRepository
.getUserWithUsernameAndServer(username, server) .getUserWithUsernameAndServer(username, server)