Crash: open private room by link. Use RoomId instead of the alias.

This commit is contained in:
ClaireG 2022-04-20 09:17:16 +02:00 committed by GitHub
parent abe07c73a4
commit e0556cd5e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

2
changelog.d/5786.bugfix Normal file
View File

@ -0,0 +1,2 @@
Open a room by link: use the actual roomId instead of the alias

View File

@ -24,7 +24,7 @@ sealed class MatrixToAction : VectorViewModelAction {
object FailedToResolveUser : MatrixToAction()
object FailedToStartChatting : MatrixToAction()
data class JoinSpace(val spaceID: String, val viaServers: List<String>?) : MatrixToAction()
data class JoinRoom(val roomId: String, val viaServers: List<String>?) : MatrixToAction()
data class JoinRoom(val roomIdOrAlias: String, val viaServers: List<String>?) : MatrixToAction()
data class OpenSpace(val spaceID: String) : MatrixToAction()
data class OpenRoom(val roomId: String) : MatrixToAction()
}

View File

@ -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())