mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
Re-organize sessionId handling
- clean session Id when leaving the room rather than in onAttach - invoke leaveRoom in onDetach only when we have a valid sessionId This avoid calling joinRoom twice in some scenarios, or calling leaveRoom before joinRoom completes successfully. Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
This commit is contained in:
parent
d31e6de5c4
commit
b2aef87b24
@ -1508,6 +1508,12 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun validSessionId() : Boolean {
|
||||||
|
return currentConversation != null &&
|
||||||
|
!TextUtils.isEmpty(currentConversation?.sessionId) &&
|
||||||
|
currentConversation?.sessionId != "0"
|
||||||
|
}
|
||||||
|
|
||||||
override fun onAttach(view: View) {
|
override fun onAttach(view: View) {
|
||||||
super.onAttach(view)
|
super.onAttach(view)
|
||||||
Log.d(TAG, "onAttach: Controller: " + System.identityHashCode(this).toString() +
|
Log.d(TAG, "onAttach: Controller: " + System.identityHashCode(this).toString() +
|
||||||
@ -1556,7 +1562,6 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
Log.d(TAG, "onAttach inConversation: " + inConversation.toString())
|
Log.d(TAG, "onAttach inConversation: " + inConversation.toString())
|
||||||
if (inConversation) {
|
if (inConversation) {
|
||||||
currentConversation?.sessionId = "0"
|
|
||||||
Log.d(TAG, "execute joinRoomWithPassword in onAttach")
|
Log.d(TAG, "execute joinRoomWithPassword in onAttach")
|
||||||
joinRoomWithPassword()
|
joinRoomWithPassword()
|
||||||
}
|
}
|
||||||
@ -1597,7 +1602,7 @@ class ChatController(args: Bundle) :
|
|||||||
!ApplicationWideCurrentRoomHolder.getInstance().isDialing
|
!ApplicationWideCurrentRoomHolder.getInstance().isDialing
|
||||||
) {
|
) {
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().clear()
|
ApplicationWideCurrentRoomHolder.getInstance().clear()
|
||||||
if (inConversation) {
|
if (inConversation && validSessionId()) {
|
||||||
leaveRoom()
|
leaveRoom()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1645,12 +1650,11 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun joinRoomWithPassword() {
|
private fun joinRoomWithPassword() {
|
||||||
Log.d(TAG, "joinRoomWithPassword start: " + (currentConversation == null).toString())
|
Log.d(TAG,
|
||||||
|
"joinRoomWithPassword start: " + (currentConversation == null).toString() +
|
||||||
|
" sessionId: " + currentConversation?.sessionId)
|
||||||
|
|
||||||
if (currentConversation == null ||
|
if (! validSessionId()) {
|
||||||
TextUtils.isEmpty(currentConversation?.sessionId) ||
|
|
||||||
currentConversation?.sessionId == "0"
|
|
||||||
) {
|
|
||||||
var apiVersion = 1
|
var apiVersion = 1
|
||||||
// FIXME Fix API checking with guests?
|
// FIXME Fix API checking with guests?
|
||||||
if (conversationUser != null) {
|
if (conversationUser != null) {
|
||||||
@ -1677,6 +1681,7 @@ class ChatController(args: Bundle) :
|
|||||||
Log.d(TAG, "joinRoomWithPassword - joinRoom - got response: " + startNanoTime)
|
Log.d(TAG, "joinRoomWithPassword - joinRoom - got response: " + startNanoTime)
|
||||||
inConversation = true
|
inConversation = true
|
||||||
currentConversation?.sessionId = roomOverall.ocs.data.sessionId
|
currentConversation?.sessionId = roomOverall.ocs.data.sessionId
|
||||||
|
Log.d(TAG, "joinRoomWithPassword - joinRoom - got response - sessionId: " + currentConversation?.sessionId)
|
||||||
|
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().session =
|
ApplicationWideCurrentRoomHolder.getInstance().session =
|
||||||
currentConversation?.sessionId
|
currentConversation?.sessionId
|
||||||
@ -1775,6 +1780,8 @@ class ChatController(args: Bundle) :
|
|||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "magicWebSocketInstance or currentConversation were null! Failed to leave the room!")
|
Log.e(TAG, "magicWebSocketInstance or currentConversation were null! Failed to leave the room!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentConversation?.sessionId = "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
override fun onError(e: Throwable) {
|
||||||
|
Loading…
Reference in New Issue
Block a user