Browse Source

fix to load conversationlist only once after login

without this fix:
after login the conversation list opened multiple times for the same user when other users already exist

reason:
proceedWithLogin() in AccountVerificationController is called multiple times because for ALL accounts (for (User user : userEntityObjectList)) the workers send their results via eventBus to

AccountVerificationController#onMessageEvent(eventStatus: EventStatus)

So depending on how many accounts exist, the ConversationList was loaded x times.

solution:
if internalAccountId is already the active one, no need to load the conversationList another time.

when there is only one account -> currentUser id and internalAccountId are the same so it would not enter the condition. Thus also allowing it when only one user exists.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 2 năm trước cách đây
mục cha
commit
ac5061d8a4

+ 21 - 17
app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.kt

@@ -450,28 +450,32 @@ class AccountVerificationController(args: Bundle? = null) : BaseController(
         Log.d(TAG, "proceedWithLogin...")
         cookieManager.cookieStore.removeAll()
 
-        val userToSetAsActive = userManager.getUserWithId(internalAccountId).blockingGet()
-        Log.d(TAG, "userToSetAsActive: " + userToSetAsActive.username)
+        if (userManager.users.blockingGet().size == 1 ||
+            userManager.currentUser.blockingGet().id != internalAccountId
+        ) {
+            val userToSetAsActive = userManager.getUserWithId(internalAccountId).blockingGet()
+            Log.d(TAG, "userToSetAsActive: " + userToSetAsActive.username)
 
-        if (userManager.setUserAsActive(userToSetAsActive).blockingGet()) {
-            if (activity != null) {
-                activity!!.runOnUiThread {
-                    if (userManager.users.blockingGet().size == 1) {
-                        val intent = Intent(context, ConversationsListActivity::class.java)
-                        startActivity(intent)
-                    } else {
-                        if (isAccountImport) {
-                            ApplicationWideMessageHolder.getInstance().messageType =
-                                ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED
+            if (userManager.setUserAsActive(userToSetAsActive).blockingGet()) {
+                if (activity != null) {
+                    activity!!.runOnUiThread {
+                        if (userManager.users.blockingGet().size == 1) {
+                            val intent = Intent(context, ConversationsListActivity::class.java)
+                            startActivity(intent)
+                        } else {
+                            if (isAccountImport) {
+                                ApplicationWideMessageHolder.getInstance().messageType =
+                                    ApplicationWideMessageHolder.MessageType.ACCOUNT_WAS_IMPORTED
+                            }
+                            val intent = Intent(context, ConversationsListActivity::class.java)
+                            startActivity(intent)
                         }
-                        val intent = Intent(context, ConversationsListActivity::class.java)
-                        startActivity(intent)
                     }
                 }
+            } else {
+                Log.e(TAG, "failed to set active user")
+                Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
             }
-        } else {
-            Log.e(TAG, "failed to set active user")
-            Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
         }
     }