Restrict to join other rooms while being in a call

When clicking on a conversation in conversation overview, restrict opening immediately.
If joinRoomWithPassword in ChatController is reached in any other way (for example by creating a new conversation while being in a call), then it's restricted to join the room.

All this is done to avoid NPE:

D/ChatController: pullChatMessages - pullChatMessages[lookIntoFuture > 0] - got response
W/System.err: java.lang.NullPointerException
W/System.err:     at com.nextcloud.talk.controllers.ChatController.modifyMessageCount(ChatController.kt:2536)
W/System.err:     at com.nextcloud.talk.controllers.ChatController.addMessagesToAdapter(ChatController.kt:2515)
W/System.err:     at com.nextcloud.talk.controllers.ChatController.processMessagesFromTheFuture(ChatController.kt:2489)
W/System.err:     at com.nextcloud.talk.controllers.ChatController.processMessages(ChatController.kt:2437)
W/System.err:     at com.nextcloud.talk.controllers.ChatController.processMessagesResponse(ChatController.kt:2398)
W/System.err:     at com.nextcloud.talk.controllers.ChatController.access$processMessagesResponse(ChatController.kt:221)
W/System.err:     at com.nextcloud.talk.controllers.ChatController$pullChatMessages$2.onNext(ChatController.kt:2309)
W/System.err:     at com.nextcloud.talk.controllers.ChatController$pullChatMessages$2.onNext(ChatController.kt:2294)
W/System.err:     at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:201)
W/System.err:     at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:255)
W/System.err:     at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:124)
W/System.err:     at android.os.Handler.handleCallback(Handler.java:883)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:100)
W/System.err:     at android.os.Looper.loop(Looper.java:224)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7590)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Known issues:
- doesn't respect handling for other instances. E.g. when receiving notification from other instance and open it.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>

Fix to always allow opening same room when being in call

Fix to set also other properties for ApplicationWideCurrentRoomHolder when joining room in chat.

Otherwise it could have been possible to not be allowed to open this chat again from conversation list while being in call.

In a next step, ApplicationWideCurrentRoomHolder should be refactored to hold the conversation itself. Maybe in a map of users to handle different instances.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-03-03 12:02:34 +01:00
parent 96c1e581fb
commit 5f2e2c5fe6
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 40 additions and 5 deletions

View File

@ -1885,8 +1885,7 @@ class ChatController(args: Bundle) :
if (validSessionId()) {
leaveRoom(null, null)
} else {
Log.d(TAG, "not leaving room (inConversation is false and/or validSessionId is false)")
// room might have already been left...
Log.d(TAG, "not leaving room (validSessionId is false)")
}
} else {
Log.e(TAG, "not leaving room...")
@ -1937,6 +1936,24 @@ class ChatController(args: Bundle) :
}
private fun joinRoomWithPassword() {
if (CallActivity.active &&
roomToken != ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken
) {
Toast.makeText(
context,
context.getString(R.string.restrict_join_other_room_while_call),
Toast.LENGTH_LONG
).show()
Log.e(
TAG,
"Restricted to open chat controller because a call in another room is active. This is an " +
"edge case which is not properly handled yet."
)
router.popToRoot()
return
}
// if ApplicationWideCurrentRoomHolder contains a session (because a call is active), then keep the sessionId
if (ApplicationWideCurrentRoomHolder.getInstance().currentRoomId ==
currentConversation!!.roomId
@ -1974,12 +1991,16 @@ class ChatController(args: Bundle) :
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onNext(roomOverall: RoomOverall) {
Log.d(TAG, "joinRoomWithPassword - joinRoom - got response: $startNanoTime")
sessionIdAfterRoomJoined = roomOverall.ocs!!.data!!.sessionId
val conversation = roomOverall.ocs!!.data!!
sessionIdAfterRoomJoined = conversation.sessionId
ApplicationWideCurrentRoomHolder.getInstance().session = conversation.sessionId
ApplicationWideCurrentRoomHolder.getInstance().currentRoomId = conversation.roomId
ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken = conversation.token
ApplicationWideCurrentRoomHolder.getInstance().userInRoom = conversationUser
logConversationInfos("joinRoomWithPassword#onNext")
ApplicationWideCurrentRoomHolder.getInstance().session = sessionIdAfterRoomJoined
// 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
// was able to finish and, therefore, that the web socket instance can be got.

View File

@ -66,6 +66,7 @@ import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.nextcloud.talk.R
import com.nextcloud.talk.activities.CallActivity
import com.nextcloud.talk.activities.MainActivity
import com.nextcloud.talk.adapters.items.ConversationItem
import com.nextcloud.talk.adapters.items.GenericTextHeaderItem
@ -120,6 +121,7 @@ import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.isUnifiedSearc
import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.isUserStatusAvailable
import com.nextcloud.talk.utils.remapchat.ConductorRemapping.remapChatController
import com.nextcloud.talk.utils.rx.SearchViewObservable.Companion.observeSearchView
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
@ -1112,6 +1114,17 @@ class ConversationsListController(bundle: Bundle) :
}
private fun openConversation(textToPaste: String? = "") {
if (CallActivity.active &&
selectedConversation!!.token != ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken
) {
Toast.makeText(
context,
context.getString(R.string.restrict_join_other_room_while_call),
Toast.LENGTH_LONG
).show()
return
}
val bundle = Bundle()
bundle.putParcelable(KEY_USER_ENTITY, currentUser)
bundle.putParcelable(KEY_ACTIVE_CONVERSATION, Parcels.wrap(selectedConversation))

View File

@ -241,6 +241,7 @@ How to translate with transifex:
<string name="nc_call_raised_hand">%1$s raised the hand</string>
<string name="raise_hand">Raise hand</string>
<string name="lower_hand">Lower hand</string>
<string name="restrict_join_other_room_while_call">"It's not possible to join other rooms while being in a call</string>
<!-- Picture in Picture -->
<string name="nc_pip_microphone_mute">Mute microphone</string>