Replace "inConversation" with check of valid session id

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-02-28 14:21:10 +01:00
parent 968593ccf7
commit 5d129ba03e
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

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