From bb0b1ed0983059be2e2584b74ef430e797f5ef81 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 3 Mar 2021 15:16:46 +0100 Subject: [PATCH] Some fixes + join actions --- .../matrixto/MatrixToBottomSheetViewModel.kt | 15 ++----- .../matrixto/MatrixToRoomSpaceFragment.kt | 14 ++++++- .../features/navigation/DefaultNavigator.kt | 24 +++++++++++ .../app/features/navigation/Navigator.kt | 2 + .../features/permalink/PermalinkHandler.kt | 40 +++++-------------- 5 files changed, 51 insertions(+), 44 deletions(-) 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 267322b58a..e608774f33 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 @@ -47,7 +47,6 @@ import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.internal.session.room.alias.RoomAliasDescription import org.matrix.android.sdk.internal.util.awaitCallback -import timber.log.Timber class MatrixToBottomSheetViewModel @AssistedInject constructor( @Assisted initialState: MatrixToBottomSheetState, @@ -118,7 +117,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( } ?.getOrNull() ?.roomId?.let { - session.getRoom(permalinkData.roomIdOrAlias) + session.getRoom(it) } } else { session.getRoom(permalinkData.roomIdOrAlias) @@ -142,7 +141,6 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( ) } } else { - val result = when (val peekResult = tryOrNull { resolveRoom(permalinkData.roomIdOrAlias) }) { is PeekResult.Success -> { RoomInfoResult.FullInfo( @@ -163,7 +161,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( ) } PeekResult.UnknownAlias -> { - RoomInfoResult.NotFound + RoomInfoResult.UnknownAlias(permalinkData.roomIdOrAlias) } null -> { RoomInfoResult.PartialInfo( @@ -201,12 +199,9 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( * main thing is trying to see if it's a space or a room */ private suspend fun resolveRoom(roomIdOrAlias: String): PeekResult { - return tryOrNull { // this should not throw as it returns a result, but better be safe - awaitCallback { - session.peekRoom(roomIdOrAlias, it) - } + return awaitCallback { + session.peekRoom(roomIdOrAlias, it) } - ?: PeekResult.PeekingNotAllowed(roomIdOrAlias, null, emptyList()) } companion object : MvRxViewModelFactory { @@ -258,7 +253,6 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( copy(startChattingState = Uninitialized) } } - } } @@ -280,7 +274,6 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor( copy(startChattingState = Uninitialized) } } - } } diff --git a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToRoomSpaceFragment.kt b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToRoomSpaceFragment.kt index 8ab2a46bad..31dc537395 100644 --- a/vector/src/main/java/im/vector/app/features/matrixto/MatrixToRoomSpaceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/matrixto/MatrixToRoomSpaceFragment.kt @@ -87,17 +87,23 @@ class MatrixToRoomSpaceFragment @Inject constructor( views.matrixToMemberPills.isVisible = false } + val joinTextRes = if (peek.roomType == RoomType.SPACE) { + R.string.join_space + } else { + R.string.join_room + } + when (peek.membership) { Membership.LEAVE, Membership.NONE -> { views.matrixToCardMainButton.isVisible = true - views.matrixToCardMainButton.text = getString(R.string.join_space) + views.matrixToCardMainButton.text = getString(joinTextRes) views.matrixToCardSecondaryButton.isVisible = false } Membership.INVITE -> { views.matrixToCardMainButton.isVisible = true views.matrixToCardSecondaryButton.isVisible = true - views.matrixToCardMainButton.text = getString(R.string.join_space) + views.matrixToCardMainButton.text = getString(joinTextRes) views.matrixToCardSecondaryButton.text = getString(R.string.decline) } Membership.JOIN -> { @@ -196,6 +202,10 @@ class MatrixToRoomSpaceFragment @Inject constructor( } } is RoomInfoResult.PartialInfo -> { + // we can try to join anyway + if (info.roomId != null) { + sharedViewModel.handle(MatrixToAction.JoinRoom(info.roomId, info.viaServers)) + } } else -> { } diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index 80cb82098b..27c29ae42b 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -54,6 +54,7 @@ import im.vector.app.features.home.room.detail.search.SearchActivity import im.vector.app.features.home.room.detail.search.SearchArgs import im.vector.app.features.home.room.filtered.FilteredRoomsActivity import im.vector.app.features.invite.InviteUsersToRoomActivity +import im.vector.app.features.matrixto.MatrixToBottomSheet import im.vector.app.features.media.AttachmentData import im.vector.app.features.media.BigImageViewerActivity import im.vector.app.features.media.VectorAttachmentViewerActivity @@ -119,6 +120,12 @@ class DefaultNavigator @Inject constructor( val args = RoomDetailArgs(roomId, eventId = null, openShareSpaceForId = spaceId.takeIf { openShareSheet }) val intent = RoomDetailActivity.newIntent(context, args) startActivity(context, intent, false) + } else { + // go back to home if we are showing room details? + // This is a bit ugly, but the navigator is supposed to know about the activity stack + if (context is RoomDetailActivity) { + context.finish() + } } } @@ -225,6 +232,23 @@ class DefaultNavigator @Inject constructor( context.startActivity(intent) } + override fun openMatrixToBottomSheet(context: Context, link: String) { + if (context is AppCompatActivity) { + val listener = object : MatrixToBottomSheet.InteractionListener { + override fun navigateToRoom(roomId: String) { + openRoom(context, roomId) + } + + override fun switchToSpace(spaceId: String) { + this@DefaultNavigator.switchToSpace(context, spaceId, null, openShareSheet = false) + } + } + // TODO check if there is already one?? + MatrixToBottomSheet.withLink(link, listener) + .show(context.supportFragmentManager, "HA#MatrixToBottomSheet") + } + } + override fun openRoomDirectory(context: Context, initialFilter: String) { val intent = RoomDirectoryActivity.getIntent(context, initialFilter) context.startActivity(intent) diff --git a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt index 225a2b89ab..489cd37987 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/Navigator.kt @@ -58,6 +58,8 @@ interface Navigator { fun openRoomPreview(context: Context, roomPreviewData: RoomPreviewData) + fun openMatrixToBottomSheet(context: Context, link: String) + fun openCreateRoom(context: Context, initialName: String = "") fun openCreateDirectRoom(context: Context) diff --git a/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt b/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt index ca1a010a03..1fea25159f 100644 --- a/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt +++ b/vector/src/main/java/im/vector/app/features/permalink/PermalinkHandler.kt @@ -22,7 +22,6 @@ import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.utils.toast import im.vector.app.features.navigation.Navigator -import im.vector.app.features.roomdirectory.roompreview.RoomPreviewData import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.schedulers.Schedulers @@ -88,6 +87,7 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti context = context, roomId = roomId, permalinkData = permalinkData, + rawLink = rawLink, buildTask = buildTask ) } @@ -137,6 +137,7 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti context: Context, roomId: String?, permalinkData: PermalinkData.RoomLink, + rawLink: Uri, buildTask: Boolean ) { val session = activeSessionHolder.getSafeActiveSession() ?: return @@ -152,40 +153,17 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti return when { membership == Membership.BAN -> context.toast(R.string.error_opening_banned_room) membership?.isActive().orFalse() -> { - if (isSpace) { -// navigator.switchToSpace(context, roomId, null) - navigator.openSpacePreview(context, roomId) - } else { + if (!isSpace && membership == Membership.JOIN) { + // If it's a room you're in, let's just open it, you can tap back if needed navigator.openRoom(context, roomId, eventId, buildTask) + } else { + // maybe open space preview navigator.openSpacePreview(context, roomId)? if already joined? + navigator.openMatrixToBottomSheet(context, rawLink.toString()) } } else -> { - if (isSpace) { - navigator.openSpacePreview(context, roomId) - } else { - if (roomSummary == null) { - // we don't know this room, try to peek - val roomPreviewData = RoomPreviewData( - roomId = roomId, - roomAlias = roomAlias, - peekFromServer = true, - buildTask = buildTask, - homeServers = permalinkData.viaParameters - ) - navigator.openRoomPreview(context, roomPreviewData) - } else { - val roomPreviewData = RoomPreviewData( - roomId = roomId, - eventId = eventId, - roomAlias = roomAlias ?: roomSummary.canonicalAlias, - roomName = roomSummary.displayName, - avatarUrl = roomSummary.avatarUrl, - buildTask = buildTask, - homeServers = permalinkData.viaParameters - ) - navigator.openRoomPreview(context, roomPreviewData) - } - } + // XXX this could trigger another server load + navigator.openMatrixToBottomSheet(context, rawLink.toString()) } } }