Some fixes + join actions

This commit is contained in:
Valere 2021-03-03 15:16:46 +01:00
parent ef42591534
commit bb0b1ed098
5 changed files with 51 additions and 44 deletions

View File

@ -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.api.util.toMatrixItem
import org.matrix.android.sdk.internal.session.room.alias.RoomAliasDescription import org.matrix.android.sdk.internal.session.room.alias.RoomAliasDescription
import org.matrix.android.sdk.internal.util.awaitCallback import org.matrix.android.sdk.internal.util.awaitCallback
import timber.log.Timber
class MatrixToBottomSheetViewModel @AssistedInject constructor( class MatrixToBottomSheetViewModel @AssistedInject constructor(
@Assisted initialState: MatrixToBottomSheetState, @Assisted initialState: MatrixToBottomSheetState,
@ -118,7 +117,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
} }
?.getOrNull() ?.getOrNull()
?.roomId?.let { ?.roomId?.let {
session.getRoom(permalinkData.roomIdOrAlias) session.getRoom(it)
} }
} else { } else {
session.getRoom(permalinkData.roomIdOrAlias) session.getRoom(permalinkData.roomIdOrAlias)
@ -142,7 +141,6 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
) )
} }
} else { } else {
val result = when (val peekResult = tryOrNull { resolveRoom(permalinkData.roomIdOrAlias) }) { val result = when (val peekResult = tryOrNull { resolveRoom(permalinkData.roomIdOrAlias) }) {
is PeekResult.Success -> { is PeekResult.Success -> {
RoomInfoResult.FullInfo( RoomInfoResult.FullInfo(
@ -163,7 +161,7 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
) )
} }
PeekResult.UnknownAlias -> { PeekResult.UnknownAlias -> {
RoomInfoResult.NotFound RoomInfoResult.UnknownAlias(permalinkData.roomIdOrAlias)
} }
null -> { null -> {
RoomInfoResult.PartialInfo( RoomInfoResult.PartialInfo(
@ -201,13 +199,10 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
* main thing is trying to see if it's a space or a room * main thing is trying to see if it's a space or a room
*/ */
private suspend fun resolveRoom(roomIdOrAlias: String): PeekResult { private suspend fun resolveRoom(roomIdOrAlias: String): PeekResult {
return tryOrNull { // this should not throw as it returns a result, but better be safe return awaitCallback {
awaitCallback {
session.peekRoom(roomIdOrAlias, it) session.peekRoom(roomIdOrAlias, it)
} }
} }
?: PeekResult.PeekingNotAllowed(roomIdOrAlias, null, emptyList())
}
companion object : MvRxViewModelFactory<MatrixToBottomSheetViewModel, MatrixToBottomSheetState> { companion object : MvRxViewModelFactory<MatrixToBottomSheetViewModel, MatrixToBottomSheetState> {
override fun create(viewModelContext: ViewModelContext, state: MatrixToBottomSheetState): MatrixToBottomSheetViewModel? { override fun create(viewModelContext: ViewModelContext, state: MatrixToBottomSheetState): MatrixToBottomSheetViewModel? {
@ -258,7 +253,6 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
copy(startChattingState = Uninitialized) copy(startChattingState = Uninitialized)
} }
} }
} }
} }
@ -280,7 +274,6 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
copy(startChattingState = Uninitialized) copy(startChattingState = Uninitialized)
} }
} }
} }
} }

View File

@ -87,17 +87,23 @@ class MatrixToRoomSpaceFragment @Inject constructor(
views.matrixToMemberPills.isVisible = false views.matrixToMemberPills.isVisible = false
} }
val joinTextRes = if (peek.roomType == RoomType.SPACE) {
R.string.join_space
} else {
R.string.join_room
}
when (peek.membership) { when (peek.membership) {
Membership.LEAVE, Membership.LEAVE,
Membership.NONE -> { Membership.NONE -> {
views.matrixToCardMainButton.isVisible = true views.matrixToCardMainButton.isVisible = true
views.matrixToCardMainButton.text = getString(R.string.join_space) views.matrixToCardMainButton.text = getString(joinTextRes)
views.matrixToCardSecondaryButton.isVisible = false views.matrixToCardSecondaryButton.isVisible = false
} }
Membership.INVITE -> { Membership.INVITE -> {
views.matrixToCardMainButton.isVisible = true views.matrixToCardMainButton.isVisible = true
views.matrixToCardSecondaryButton.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) views.matrixToCardSecondaryButton.text = getString(R.string.decline)
} }
Membership.JOIN -> { Membership.JOIN -> {
@ -196,6 +202,10 @@ class MatrixToRoomSpaceFragment @Inject constructor(
} }
} }
is RoomInfoResult.PartialInfo -> { is RoomInfoResult.PartialInfo -> {
// we can try to join anyway
if (info.roomId != null) {
sharedViewModel.handle(MatrixToAction.JoinRoom(info.roomId, info.viaServers))
}
} }
else -> { else -> {
} }

View File

@ -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.detail.search.SearchArgs
import im.vector.app.features.home.room.filtered.FilteredRoomsActivity import im.vector.app.features.home.room.filtered.FilteredRoomsActivity
import im.vector.app.features.invite.InviteUsersToRoomActivity 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.AttachmentData
import im.vector.app.features.media.BigImageViewerActivity import im.vector.app.features.media.BigImageViewerActivity
import im.vector.app.features.media.VectorAttachmentViewerActivity 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 args = RoomDetailArgs(roomId, eventId = null, openShareSpaceForId = spaceId.takeIf { openShareSheet })
val intent = RoomDetailActivity.newIntent(context, args) val intent = RoomDetailActivity.newIntent(context, args)
startActivity(context, intent, false) 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) 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) { override fun openRoomDirectory(context: Context, initialFilter: String) {
val intent = RoomDirectoryActivity.getIntent(context, initialFilter) val intent = RoomDirectoryActivity.getIntent(context, initialFilter)
context.startActivity(intent) context.startActivity(intent)

View File

@ -58,6 +58,8 @@ interface Navigator {
fun openRoomPreview(context: Context, roomPreviewData: RoomPreviewData) fun openRoomPreview(context: Context, roomPreviewData: RoomPreviewData)
fun openMatrixToBottomSheet(context: Context, link: String)
fun openCreateRoom(context: Context, initialName: String = "") fun openCreateRoom(context: Context, initialName: String = "")
fun openCreateDirectRoom(context: Context) fun openCreateDirectRoom(context: Context)

View File

@ -22,7 +22,6 @@ import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.utils.toast import im.vector.app.core.utils.toast
import im.vector.app.features.navigation.Navigator import im.vector.app.features.navigation.Navigator
import im.vector.app.features.roomdirectory.roompreview.RoomPreviewData
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
@ -88,6 +87,7 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti
context = context, context = context,
roomId = roomId, roomId = roomId,
permalinkData = permalinkData, permalinkData = permalinkData,
rawLink = rawLink,
buildTask = buildTask buildTask = buildTask
) )
} }
@ -137,6 +137,7 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti
context: Context, context: Context,
roomId: String?, roomId: String?,
permalinkData: PermalinkData.RoomLink, permalinkData: PermalinkData.RoomLink,
rawLink: Uri,
buildTask: Boolean buildTask: Boolean
) { ) {
val session = activeSessionHolder.getSafeActiveSession() ?: return val session = activeSessionHolder.getSafeActiveSession() ?: return
@ -152,40 +153,17 @@ class PermalinkHandler @Inject constructor(private val activeSessionHolder: Acti
return when { return when {
membership == Membership.BAN -> context.toast(R.string.error_opening_banned_room) membership == Membership.BAN -> context.toast(R.string.error_opening_banned_room)
membership?.isActive().orFalse() -> { membership?.isActive().orFalse() -> {
if (isSpace) { if (!isSpace && membership == Membership.JOIN) {
// navigator.switchToSpace(context, roomId, null) // If it's a room you're in, let's just open it, you can tap back if needed
navigator.openSpacePreview(context, roomId)
} else {
navigator.openRoom(context, roomId, eventId, buildTask) navigator.openRoom(context, roomId, eventId, buildTask)
} else {
// maybe open space preview navigator.openSpacePreview(context, roomId)? if already joined?
navigator.openMatrixToBottomSheet(context, rawLink.toString())
} }
} }
else -> { else -> {
if (isSpace) { // XXX this could trigger another server load
navigator.openSpacePreview(context, roomId) navigator.openMatrixToBottomSheet(context, rawLink.toString())
} 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)
}
}
} }
} }
} }