fix(deeplink): ask before joining the call of a voice room opened by a link

A nextcloudtalk:// link to a known conversation opened its chat right away,
and the chat of a voice room joins its call as soon as it has joined the
room. Such a link now opens the voice room through the conversation list,
like a conversation shortcut, which asks whether to join the call, as when
it is opened from the list.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <[email protected]>
This commit is contained in:
Marcel Hibbe committed 2026-11-03 11:25:31 +01:00
1 parent 581f64f238
commit 3e661aa2f2
4 files changed
+55 -10

No files matched your search

@@ -24,6 +24,7 @@ import com.nextcloud.talk.activities.DeepLinkRoutingViewModel.RoutingState
import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.conversationlist.ConversationsListActivity
import com.nextcloud.talk.utils.AppTasks
import com.nextcloud.talk.utils.ShortcutManagerHelper
/**
* Shows the routing of the deep links and contact chats that [DeepLinkActivity] passes on to the conversation list
@@ -148,6 +149,10 @@ class DeepLinkRouting(
activity.startActivities(arrayOf(listIntent, chatIntent))
}
}
// the list of its account asks whether to join the call, see ConversationsListActivity.handleConversation
is Destination.VoiceRoom -> activity.startActivity(
ShortcutManagerHelper.createConversationIntent(activity, destination.roomToken, destination.userId)
)
}
}
@@ -23,9 +23,11 @@ import com.nextcloud.talk.conversationlist.data.OfflineConversationsRepository
import com.nextcloud.talk.conversationlist.data.network.OfflineFirstConversationsRepository.ConversationResult
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.logger.Logger
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.conversations.ConversationEnums
import com.nextcloud.talk.users.DefaultAccountProvider
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ConversationUtils.checkIfVoiceRoom
import com.nextcloud.talk.utils.DeepLinkHandler
import com.nextcloud.talk.utils.InternalEntryPoint
import com.nextcloud.talk.utils.ShortcutManagerHelper
@@ -97,6 +99,12 @@ class DeepLinkRoutingViewModel @Inject constructor(
/** The chat of [roomToken], above the conversation list of the account [userId]. */
data class Chat(val userId: Long, val roomToken: String) : Destination
/**
* The voice room [roomToken] of the account [userId], which its conversation list opens like a conversation
* shortcut: it asks whether to join the call, which opening its chat would start right away.
*/
data class VoiceRoom(val userId: Long, val roomToken: String) : Destination
}
sealed interface RoutingState {
@@ -225,12 +233,18 @@ class DeepLinkRoutingViewModel @Inject constructor(
return
}
val user = resolveTargetUser(users, link, defaultUserAmong(users))
if (user == null) {
open(Destination.ConversationList, R.string.nc_no_account_for_server, isLongMessage = true)
return
}
val conversation = knownConversation(user, link.roomToken)
when {
user == null -> open(Destination.ConversationList, R.string.nc_no_account_for_server, isLongMessage = true)
isKnownConversation(user, link.roomToken) -> openDeepLinkConversation(user, link.roomToken)
else -> ask(RoutingState.AskToJoin(link.serverUrl.toUri().host ?: link.serverUrl)) {
conversation == null -> ask(RoutingState.AskToJoin(link.serverUrl.toUri().host ?: link.serverUrl)) {
openDeepLinkConversation(user, link.roomToken)
}
// another app must not start a call
conversation.checkIfVoiceRoom() -> open(Destination.VoiceRoom(user.id!!, link.roomToken))
else -> openDeepLinkConversation(user, link.roomToken)
}
}
@@ -238,11 +252,16 @@ class DeepLinkRoutingViewModel @Inject constructor(
private suspend fun defaultUserAmong(users: List<User>): User? =
defaultAccountProvider.getDefaultUser()?.takeIf { default -> users.any { it.id == default.id } }
/** Whether [roomToken] is a conversation of [user], see [isStoredOrSynced]. */
private suspend fun isKnownConversation(user: User, roomToken: String): Boolean =
/** The conversation [roomToken] of [user], stored or after a sync like [isStoredOrSynced], else null. */
private suspend fun knownConversation(user: User, roomToken: String): ConversationModel? {
var conversation: ConversationModel? = null
isStoredOrSynced(user) {
conversationsRepository.observeConversation(user.id!!, roomToken).first() is ConversationResult.Found
val result = conversationsRepository.observeConversation(user.id!!, roomToken).first()
conversation = (result as? ConversationResult.Found)?.conversation
conversation != null
}
return conversation
}
// The account isn't made active here: while the lock screen covers the list, or while it is stopped, its
// onRestart would relaunch it for the new default account and drop this pending chat. The list of the account that
@@ -258,9 +258,12 @@ object ShortcutManagerHelper {
* share targets: the system starts a shortcut as the app that published it, so it can target the internal entry
* point of the conversation list, which takes the account and conversation from its extras.
*/
fun createConversationIntent(context: Context, roomToken: String, user: User): Intent? {
val userId = user.id ?: return null
return ConversationsListActivity.createIntent(context).apply {
fun createConversationIntent(context: Context, roomToken: String, user: User): Intent? =
user.id?.let { createConversationIntent(context, roomToken, it) }
/** Like [createConversationIntent], for the account with the internal id [userId]. */
fun createConversationIntent(context: Context, roomToken: String, userId: Long): Intent =
ConversationsListActivity.createIntent(context).apply {
action = Intent.ACTION_VIEW
putExtra(BundleKeys.KEY_ROOM_TOKEN, roomToken)
putExtra(BundleKeys.KEY_INTERNAL_USER_ID, userId)
@@ -268,7 +271,6 @@ object ShortcutManagerHelper {
// intent; the list on top of it gets it in onNewIntent instead.
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
}
}
/**
* Creates the intent that opens the conversation [roomToken] of [user] through its nextcloudtalk:// deep link, or
@@ -24,9 +24,11 @@ import com.nextcloud.talk.activities.DeepLinkRoutingViewModel.RoutingState
import com.nextcloud.talk.conversationlist.data.OfflineConversationsRepository
import com.nextcloud.talk.conversationlist.data.network.OfflineFirstConversationsRepository.ConversationResult
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.capabilities.CapabilitiesDto
import com.nextcloud.talk.models.json.capabilities.SpreedCapabilityDto
import com.nextcloud.talk.models.json.conversations.ConversationDto
import com.nextcloud.talk.models.json.conversations.ConversationEnums
import com.nextcloud.talk.models.json.conversations.RoomOCS
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.users.DefaultAccountProvider
@@ -213,6 +215,23 @@ class DeepLinkRoutingViewModelTest {
assertEquals(RoutingState.Open(Destination.Chat(alice.id!!, TOKEN)), viewModel.state.value)
}
@Test
fun `a deep link to a voice room lets the conversation list ask whether to join its call`() =
runTest(dispatcher) {
// its chat would start the call right away
val voiceRoom = mock<ConversationModel> {
on { attributes } doReturn ConversationEnums.ATTRIBUTE_IS_VOICE_ROOM
}
val repository = mock<OfflineConversationsRepository> {
on { observeConversation(alice.id!!, TOKEN) } doReturn flowOf(ConversationResult.Found(voiceRoom))
}
viewModel = createViewModel(repository)
viewModel.route(deepLink)
advanceUntilIdle()
assertEquals(RoutingState.Open(Destination.VoiceRoom(alice.id!!, TOKEN)), viewModel.state.value)
}
@Test
fun `a deep link to a conversation of another account opens it without making that account active`() =
runTest(dispatcher) {