mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-24 14:58:13 +08:00
Some fixes + join actions
This commit is contained in:
parent
ef42591534
commit
bb0b1ed098
@ -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<MatrixToBottomSheetViewModel, MatrixToBottomSheetState> {
|
||||
@ -258,7 +253,6 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
|
||||
copy(startChattingState = Uninitialized)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +274,6 @@ class MatrixToBottomSheetViewModel @AssistedInject constructor(
|
||||
copy(startChattingState = Uninitialized)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 -> {
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user