diff --git a/changelog.d/5786.bugfix b/changelog.d/5786.bugfix new file mode 100644 index 0000000000..90c937961e --- /dev/null +++ b/changelog.d/5786.bugfix @@ -0,0 +1,2 @@ +Open a room by link: use the actual roomId instead of the alias + diff --git a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToAction.kt b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToAction.kt index f38049640d..25db811600 100644 --- a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToAction.kt +++ b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToAction.kt @@ -24,7 +24,7 @@ sealed class MatrixToAction : VectorViewModelAction { object FailedToResolveUser : MatrixToAction() object FailedToStartChatting : MatrixToAction() data class JoinSpace(val spaceID: String, val viaServers: List?) : MatrixToAction() - data class JoinRoom(val roomId: String, val viaServers: List?) : MatrixToAction() + data class JoinRoom(val roomIdOrAlias: String, val viaServers: List?) : MatrixToAction() data class OpenSpace(val spaceID: String) : MatrixToAction() data class OpenRoom(val roomId: String) : MatrixToAction() } diff --git a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt index 04c2c8dd44..6d0e380bc9 100644 --- a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToBottomSheetViewModel.kt @@ -33,6 +33,7 @@ import im.vector.app.core.resources.StringProvider import im.vector.app.features.createdirect.DirectRoomHelper import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import org.matrix.android.sdk.api.MatrixPatterns import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.permalinks.PermalinkData @@ -296,8 +297,12 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( } viewModelScope.launch { try { - session.joinRoom(action.roomId, null, action.viaServers?.take(3) ?: emptyList()) - _viewEvents.post(MatrixToViewEvents.NavigateToRoom(action.roomId)) + session.joinRoom( + roomIdOrAlias = action.roomIdOrAlias, + reason = null, + viaServers = action.viaServers?.take(3) ?: emptyList() + ) + _viewEvents.post(MatrixToViewEvents.NavigateToRoom(getRoomIdFromRoomIdOrAlias(action.roomIdOrAlias))) } catch (failure: Throwable) { _viewEvents.post(MatrixToViewEvents.ShowModalError(errorFormatter.toHumanReadable(failure))) } finally { @@ -309,6 +314,12 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( } } + private suspend fun getRoomIdFromRoomIdOrAlias(roomIdOrAlias: String): String { + return if (MatrixPatterns.isRoomAlias(roomIdOrAlias)) { + session.getRoomIdByAlias(roomIdOrAlias, true).get().roomId + } else roomIdOrAlias + } + private fun handleStartChatting(action: MatrixToAction.StartChattingWithUser) { setState { copy(startChattingState = Loading())