Browse Source

Replace "inConversation" with check of valid session id

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 2 years ago
parent
commit
5d129ba03e
1 changed files with 7 additions and 13 deletions
  1. 7 13
      app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

+ 7 - 13
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -256,7 +256,6 @@ class ChatController(args: Bundle) :
     private val roomPassword: String
     var credentials: String? = null
     var currentConversation: Conversation? = null
-    var inConversation = false
     private var historyRead = false
     private var globalLastKnownFutureMessageId = -1
     private var globalLastKnownPastMessageId = -1
@@ -388,7 +387,7 @@ class ChatController(args: Bundle) :
                         checkShowMessageInputView()
                         checkLobbyState()
 
-                        if (!inConversation) {
+                        if (!validSessionId()) {
                             joinRoomWithPassword()
                         } else {
                             Log.d(TAG, "already inConversation. joinRoomWithPassword is skipped")
@@ -1851,8 +1850,7 @@ class ChatController(args: Bundle) :
 
         cancelNotificationsForCurrentConversation()
 
-        Log.d(TAG, "onAttach inConversation: $inConversation")
-        if (inConversation) {
+        if (!validSessionId()) {
             Log.d(TAG, "execute joinRoomWithPassword in onAttach")
             joinRoomWithPassword()
         }
@@ -1901,7 +1899,7 @@ class ChatController(args: Bundle) :
 
         if (conversationUser != null && isActivityNotChangingConfigurations() && isNotInCall()) {
             ApplicationWideCurrentRoomHolder.getInstance().clear()
-            if (inConversation && validSessionId()) {
+            if (validSessionId()) {
                 leaveRoom(null, null)
             } else {
                 Log.d(TAG, "not leaving room (inConversation is false and/or validSessionId is false)")
@@ -1952,7 +1950,6 @@ class ChatController(args: Bundle) :
         currentlyPlayedVoiceMessage?.let { stopMediaPlayer(it) }
 
         adapter = null
-        inConversation = false
         Log.d(TAG, "inConversation was set to false!")
     }
 
@@ -1983,7 +1980,6 @@ class ChatController(args: Bundle) :
                     @Suppress("Detekt.TooGenericExceptionCaught")
                     override fun onNext(roomOverall: RoomOverall) {
                         Log.d(TAG, "joinRoomWithPassword - joinRoom - got response: $startNanoTime")
-                        inConversation = true
                         currentConversation?.sessionId = roomOverall.ocs!!.data!!.sessionId
 
                         logConversationInfos("joinRoomWithPassword#onNext")
@@ -2035,7 +2031,6 @@ class ChatController(args: Bundle) :
         } else {
             Log.d(TAG, "sessionID was valid -> skip joinRoom")
 
-            inConversation = true
             ApplicationWideCurrentRoomHolder.getInstance().session = currentConversation?.sessionId
             if (webSocketInstance != null) {
                 webSocketInstance?.joinRoomWithRoomTokenAndSession(
@@ -2226,7 +2221,7 @@ class ChatController(args: Bundle) :
     }
 
     fun pullChatMessages(lookIntoFuture: Int, setReadMarker: Int = 1, xChatLastCommonRead: Int? = null) {
-        if (!inConversation) {
+        if (!validSessionId()) {
             return
         }
 
@@ -2406,7 +2401,7 @@ class ChatController(args: Bundle) :
 
             historyRead = true
 
-            if (!lookingIntoFuture && inConversation) {
+            if (!lookingIntoFuture && validSessionId()) {
                 pullChatMessages(1)
             }
         }
@@ -2442,7 +2437,7 @@ class ChatController(args: Bundle) :
         updateReadStatusOfAllMessages(xChatLastCommonRead)
         adapter?.notifyDataSetChanged()
 
-        if (inConversation) {
+        if (validSessionId()) {
             pullChatMessages(1, 1, xChatLastCommonRead)
         }
     }
@@ -2638,7 +2633,7 @@ class ChatController(args: Bundle) :
     }
 
     override fun onLoadMore(page: Int, totalItemsCount: Int) {
-        if (!historyRead && inConversation) {
+        if (!historyRead && validSessionId()) {
             pullChatMessages(0)
         }
     }
@@ -3504,7 +3499,6 @@ class ChatController(args: Bundle) :
         Log.d(TAG, " | roomToken: $roomToken")
         Log.d(TAG, " | currentConversation?.displayName: ${currentConversation?.displayName}")
         Log.d(TAG, " | currentConversation?.sessionId: ${currentConversation?.sessionId}")
-        Log.d(TAG, " | inConversation: $inConversation")
         Log.d(TAG, " |-----------------------------------------------")
     }