mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-31 08:35:19 +01:00
Merge pull request #2808 from nextcloud/bugfix/2060/fixDuplicatedMessages
Avoid duplicated messages / Fix messages not being displayed
This commit is contained in:
commit
6536ebb9a3
@ -1591,7 +1591,7 @@ public class CallActivity extends CallBaseActivity {
|
|||||||
Log.d(TAG, " new callSession by joinRoom= " + callSession);
|
Log.d(TAG, " new callSession by joinRoom= " + callSession);
|
||||||
|
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().setSession(callSession);
|
ApplicationWideCurrentRoomHolder.getInstance().setSession(callSession);
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomId(roomId);
|
ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomId(conversation.getRoomId());
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomToken(roomToken);
|
ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomToken(roomToken);
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().setUserInRoom(conversationUser);
|
ApplicationWideCurrentRoomHolder.getInstance().setUserInRoom(conversationUser);
|
||||||
callOrJoinRoomViaWebSocket();
|
callOrJoinRoomViaWebSocket();
|
||||||
|
@ -251,12 +251,12 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
val disposables = DisposableSet()
|
val disposables = DisposableSet()
|
||||||
|
|
||||||
|
var sessionIdAfterRoomJoined: String? = null
|
||||||
var roomToken: String? = null
|
var roomToken: String? = null
|
||||||
val conversationUser: User?
|
val conversationUser: User?
|
||||||
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 +388,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")
|
||||||
@ -527,13 +527,10 @@ class ChatController(args: Bundle) :
|
|||||||
override fun onViewBound(view: View) {
|
override fun onViewBound(view: View) {
|
||||||
Log.d(TAG, "onViewBound: " + System.identityHashCode(this).toString())
|
Log.d(TAG, "onViewBound: " + System.identityHashCode(this).toString())
|
||||||
actionBar?.show()
|
actionBar?.show()
|
||||||
var adapterWasNull = false
|
|
||||||
|
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
binding?.progressBar?.visibility = View.VISIBLE
|
binding?.progressBar?.visibility = View.VISIBLE
|
||||||
|
|
||||||
adapterWasNull = true
|
|
||||||
|
|
||||||
val messageHolders = MessageHolders()
|
val messageHolders = MessageHolders()
|
||||||
val profileBottomSheet = ProfileBottomSheet(ncApi, conversationUser!!, router)
|
val profileBottomSheet = ProfileBottomSheet(ncApi, conversationUser!!, router)
|
||||||
|
|
||||||
@ -918,14 +915,6 @@ class ChatController(args: Bundle) :
|
|||||||
setTitle()
|
setTitle()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adapterWasNull) {
|
|
||||||
Log.d(TAG, "starting for the first time (because adapter was null)")
|
|
||||||
if (TextUtils.isEmpty(roomToken)) {
|
|
||||||
handleFromNotification()
|
|
||||||
} else {
|
|
||||||
getRoomInfo()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.onViewBound(view)
|
super.onViewBound(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1788,8 +1777,8 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
private fun validSessionId(): Boolean {
|
private fun validSessionId(): Boolean {
|
||||||
return currentConversation != null &&
|
return currentConversation != null &&
|
||||||
!TextUtils.isEmpty(currentConversation?.sessionId) &&
|
sessionIdAfterRoomJoined?.isNotEmpty() == true &&
|
||||||
currentConversation?.sessionId != "0"
|
sessionIdAfterRoomJoined != "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||||
@ -1808,10 +1797,6 @@ class ChatController(args: Bundle) :
|
|||||||
activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener { v -> showConversationInfoScreen() }
|
activity?.findViewById<View>(R.id.toolbar)?.setOnClickListener { v -> showConversationInfoScreen() }
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().currentRoomId = roomId
|
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken = roomToken
|
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().userInRoom = conversationUser
|
|
||||||
|
|
||||||
val smileyButton = binding?.messageInputView?.findViewById<ImageButton>(R.id.smileyButton)
|
val smileyButton = binding?.messageInputView?.findViewById<ImageButton>(R.id.smileyButton)
|
||||||
|
|
||||||
emojiPopup = binding?.messageInputView?.inputEditText?.let {
|
emojiPopup = binding?.messageInputView?.inputEditText?.let {
|
||||||
@ -1851,10 +1836,10 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
cancelNotificationsForCurrentConversation()
|
cancelNotificationsForCurrentConversation()
|
||||||
|
|
||||||
Log.d(TAG, "onAttach inConversation: $inConversation")
|
if (TextUtils.isEmpty(roomToken)) {
|
||||||
if (inConversation) {
|
handleFromNotification()
|
||||||
Log.d(TAG, "execute joinRoomWithPassword in onAttach")
|
} else {
|
||||||
joinRoomWithPassword()
|
getRoomInfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1901,7 +1886,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,11 +1937,21 @@ 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!")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun joinRoomWithPassword() {
|
private fun joinRoomWithPassword() {
|
||||||
|
// if ApplicationWideCurrentRoomHolder contains a session (because a call is active), then keep the sessionId
|
||||||
|
if (ApplicationWideCurrentRoomHolder.getInstance().currentRoomId ==
|
||||||
|
currentConversation!!.roomId
|
||||||
|
) {
|
||||||
|
sessionIdAfterRoomJoined = ApplicationWideCurrentRoomHolder.getInstance().session
|
||||||
|
|
||||||
|
ApplicationWideCurrentRoomHolder.getInstance().currentRoomId = roomId
|
||||||
|
ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken = roomToken
|
||||||
|
ApplicationWideCurrentRoomHolder.getInstance().userInRoom = conversationUser
|
||||||
|
}
|
||||||
|
|
||||||
if (!validSessionId()) {
|
if (!validSessionId()) {
|
||||||
Log.d(TAG, "sessionID was not valid -> joinRoom")
|
Log.d(TAG, "sessionID was not valid -> joinRoom")
|
||||||
var apiVersion = 1
|
var apiVersion = 1
|
||||||
@ -1983,13 +1978,11 @@ 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
|
sessionIdAfterRoomJoined = roomOverall.ocs!!.data!!.sessionId
|
||||||
currentConversation?.sessionId = roomOverall.ocs!!.data!!.sessionId
|
|
||||||
|
|
||||||
logConversationInfos("joinRoomWithPassword#onNext")
|
logConversationInfos("joinRoomWithPassword#onNext")
|
||||||
|
|
||||||
ApplicationWideCurrentRoomHolder.getInstance().session =
|
ApplicationWideCurrentRoomHolder.getInstance().session = sessionIdAfterRoomJoined
|
||||||
currentConversation?.sessionId
|
|
||||||
|
|
||||||
// FIXME The web socket should be set up in onAttach(). It is currently setup after joining the
|
// FIXME The web socket should be set up in onAttach(). It is currently setup after joining the
|
||||||
// room to "ensure" (rather, increase the chances) that the WebsocketConnectionsWorker job
|
// room to "ensure" (rather, increase the chances) that the WebsocketConnectionsWorker job
|
||||||
@ -2011,7 +2004,7 @@ class ChatController(args: Bundle) :
|
|||||||
if (webSocketInstance != null) {
|
if (webSocketInstance != null) {
|
||||||
webSocketInstance?.joinRoomWithRoomTokenAndSession(
|
webSocketInstance?.joinRoomWithRoomTokenAndSession(
|
||||||
roomToken!!,
|
roomToken!!,
|
||||||
currentConversation?.sessionId
|
sessionIdAfterRoomJoined
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (startCallFromNotification != null && startCallFromNotification ?: false) {
|
if (startCallFromNotification != null && startCallFromNotification ?: false) {
|
||||||
@ -2035,12 +2028,10 @@ 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
|
|
||||||
if (webSocketInstance != null) {
|
if (webSocketInstance != null) {
|
||||||
webSocketInstance?.joinRoomWithRoomTokenAndSession(
|
webSocketInstance?.joinRoomWithRoomTokenAndSession(
|
||||||
roomToken!!,
|
roomToken!!,
|
||||||
currentConversation?.sessionId
|
sessionIdAfterRoomJoined
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
checkLobbyState()
|
checkLobbyState()
|
||||||
@ -2094,7 +2085,7 @@ class ChatController(args: Bundle) :
|
|||||||
if (webSocketInstance != null && currentConversation != null) {
|
if (webSocketInstance != null && currentConversation != null) {
|
||||||
webSocketInstance?.joinRoomWithRoomTokenAndSession(
|
webSocketInstance?.joinRoomWithRoomTokenAndSession(
|
||||||
"",
|
"",
|
||||||
currentConversation?.sessionId
|
sessionIdAfterRoomJoined
|
||||||
)
|
)
|
||||||
} 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!")
|
||||||
@ -2107,7 +2098,7 @@ class ChatController(args: Bundle) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentConversation?.sessionId = "0"
|
sessionIdAfterRoomJoined = "0"
|
||||||
|
|
||||||
if (remapChatModel != null && funToCallWhenLeaveSuccessful != null) {
|
if (remapChatModel != null && funToCallWhenLeaveSuccessful != null) {
|
||||||
Log.d(TAG, "a callback action was set and is now executed because room was left successfully")
|
Log.d(TAG, "a callback action was set and is now executed because room was left successfully")
|
||||||
@ -2226,7 +2217,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 +2397,7 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
historyRead = true
|
historyRead = true
|
||||||
|
|
||||||
if (!lookingIntoFuture && inConversation) {
|
if (!lookingIntoFuture && validSessionId()) {
|
||||||
pullChatMessages(1)
|
pullChatMessages(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2442,7 +2433,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 +2629,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3503,8 +3494,7 @@ class ChatController(args: Bundle) :
|
|||||||
Log.d(TAG, " | ChatController: " + System.identityHashCode(this).toString())
|
Log.d(TAG, " | ChatController: " + System.identityHashCode(this).toString())
|
||||||
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, " | sessionIdAfterRoomJoined: $sessionIdAfterRoomJoined")
|
||||||
Log.d(TAG, " | inConversation: $inConversation")
|
|
||||||
Log.d(TAG, " |-----------------------------------------------")
|
Log.d(TAG, " |-----------------------------------------------")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user