From e277deece55925940121865272f4a0a3ac1335c4 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 16 Jun 2021 17:35:00 +0200 Subject: [PATCH] Add error feedback when joining space rooms --- newsfragment/3207.bugfix | 1 + .../home/room/list/RoomSummaryItemFactory.kt | 16 ++++++++++++++-- .../home/room/list/SpaceChildInfoItem.kt | 5 +++++ .../spaces/explore/SpaceDirectoryController.kt | 14 ++++++++++++-- .../spaces/explore/SpaceDirectoryViewModel.kt | 9 +++++---- .../src/main/res/layout/item_suggested_room.xml | 15 +++++++++++++-- vector/src/main/res/values/strings.xml | 1 + 7 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 newsfragment/3207.bugfix diff --git a/newsfragment/3207.bugfix b/newsfragment/3207.bugfix new file mode 100644 index 0000000000..162485907b --- /dev/null +++ b/newsfragment/3207.bugfix @@ -0,0 +1 @@ +Space Explore Rooms no feedback on failed to join \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index f0380b80be..17d96f210f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -17,11 +17,13 @@ package im.vector.app.features.home.room.list import com.airbnb.mvrx.Async +import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Loading import im.vector.app.R import im.vector.app.core.date.DateFormatKind import im.vector.app.core.date.VectorDateFormatter import im.vector.app.core.epoxy.VectorEpoxyModel +import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.resources.StringProvider import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.format.DisplayableEventFormatter @@ -37,7 +39,8 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor private val dateFormatter: VectorDateFormatter, private val stringProvider: StringProvider, private val typingHelper: TypingHelper, - private val avatarRenderer: AvatarRenderer) { + private val avatarRenderer: AvatarRenderer, + private val errorFormatter: ErrorFormatter) { fun create(roomSummary: RoomSummary, roomChangeMembershipStates: Map, @@ -55,12 +58,21 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor fun createSuggestion(spaceChildInfo: SpaceChildInfo, suggestedRoomJoiningStates: Map>, listener: RoomListListener?): VectorEpoxyModel<*> { + val error = (suggestedRoomJoiningStates[spaceChildInfo.childRoomId] as? Fail)?.error return SpaceChildInfoItem_() .id("sug_${spaceChildInfo.childRoomId}") .matrixItem(spaceChildInfo.toMatrixItem()) .avatarRenderer(avatarRenderer) .topic(spaceChildInfo.topic) - .buttonLabel(stringProvider.getString(R.string.join)) + .errorLabel( + error?.let { + stringProvider.getString(R.string.error_failed_to_join_room, errorFormatter.toHumanReadable(it)) + } + ) + .buttonLabel( + if (error != null) stringProvider.getString(R.string.global_retry) + else stringProvider.getString(R.string.join) + ) .loading(suggestedRoomJoiningStates[spaceChildInfo.childRoomId] is Loading) .memberCount(spaceChildInfo.activeMemberCount ?: 0) .buttonClickListener { listener?.onJoinSuggestedRoom(spaceChildInfo) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SpaceChildInfoItem.kt b/vector/src/main/java/im/vector/app/features/home/room/list/SpaceChildInfoItem.kt index 61fcd1ba86..99cbd45294 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SpaceChildInfoItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/SpaceChildInfoItem.kt @@ -33,6 +33,7 @@ import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.onClick +import im.vector.app.core.extensions.setTextOrHide import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.themes.ThemeUtils import me.gujun.android.span.image @@ -52,6 +53,7 @@ abstract class SpaceChildInfoItem : VectorEpoxyModel( @EpoxyAttribute var loading: Boolean = false @EpoxyAttribute var buttonLabel: String? = null + @EpoxyAttribute var errorLabel: String? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var itemLongClickListener: View.OnLongClickListener? = null @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var itemClickListener: ClickListener? = null @@ -97,6 +99,8 @@ abstract class SpaceChildInfoItem : VectorEpoxyModel( holder.joinButton.isVisible = true } + holder.errorTextView.setTextOrHide(errorLabel) + holder.joinButton.onClick { // local echo holder.joinButton.isEnabled = false @@ -120,5 +124,6 @@ abstract class SpaceChildInfoItem : VectorEpoxyModel( val descriptionText by bind(R.id.suggestedRoomDescription) val avatarImageView by bind(R.id.roomAvatarImageView) val rootView by bind(R.id.itemRoomLayout) + val errorTextView by bind(R.id.inlineErrorText) } } diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt index 34bb50b871..1e67da7a4d 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt @@ -35,6 +35,7 @@ import im.vector.app.features.home.room.list.spaceChildInfoItem import me.gujun.android.span.span import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.MatrixError.Companion.M_UNRECOGNIZED +import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo import org.matrix.android.sdk.api.util.toMatrixItem @@ -127,6 +128,7 @@ class SpaceDirectoryController @Inject constructor( val isSpace = info.roomType == RoomType.SPACE val isJoined = data?.joinedRoomsIds?.contains(info.childRoomId) == true val isLoading = data?.changeMembershipStates?.get(info.childRoomId)?.isInProgress() ?: false + val error = (data?.changeMembershipStates?.get(info.childRoomId) as? ChangeMembershipState.FailedJoining)?.throwable // if it's known use that matrixItem because it would have a better computed name val matrixItem = data?.knownRoomSummaries?.find { it.roomId == info.childRoomId }?.toMatrixItem() ?: info.toMatrixItem() @@ -135,11 +137,19 @@ class SpaceDirectoryController @Inject constructor( matrixItem(matrixItem) avatarRenderer(host.avatarRenderer) topic(info.topic) + errorLabel( + error?.let { + host.stringProvider.getString(R.string.error_failed_to_join_room, host.errorFormatter.toHumanReadable(it)) + } + ) memberCount(info.activeMemberCount ?: 0) loading(isLoading) buttonLabel( - if (isJoined) host.stringProvider.getString(R.string.action_open) - else host.stringProvider.getString(R.string.join) + when { + error != null -> host.stringProvider.getString(R.string.global_retry) + isJoined -> host.stringProvider.getString(R.string.action_open) + else -> host.stringProvider.getString(R.string.join) + } ) apply { if (isSpace) { diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt index 3d3e1dac65..de31f43322 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryViewModel.kt @@ -188,20 +188,21 @@ class SpaceDirectoryViewModel @AssistedInject constructor( private fun handleJoinOrOpen(spaceChildInfo: SpaceChildInfo) = withState { state -> val isSpace = spaceChildInfo.roomType == RoomType.SPACE - if (state.joinedRoomsIds.contains(spaceChildInfo.childRoomId)) { + val childId = spaceChildInfo.childRoomId + if (state.joinedRoomsIds.contains(childId)) { if (isSpace) { handle(SpaceDirectoryViewAction.ExploreSubSpace(spaceChildInfo)) } else { - _viewEvents.post(SpaceDirectoryViewEvents.NavigateToRoom(spaceChildInfo.childRoomId)) + _viewEvents.post(SpaceDirectoryViewEvents.NavigateToRoom(childId)) } } else { // join viewModelScope.launch { try { if (isSpace) { - session.spaceService().joinSpace(spaceChildInfo.childRoomId, null, spaceChildInfo.viaServers) + session.spaceService().joinSpace(childId, null, spaceChildInfo.viaServers) } else { - session.joinRoom(spaceChildInfo.childRoomId, null, spaceChildInfo.viaServers) + session.joinRoom(childId, null, spaceChildInfo.viaServers) } } catch (failure: Throwable) { Timber.e(failure, "## Space: Failed to join room or subspace") diff --git a/vector/src/main/res/layout/item_suggested_room.xml b/vector/src/main/res/layout/item_suggested_room.xml index 28803daef1..bc8dd03542 100644 --- a/vector/src/main/res/layout/item_suggested_room.xml +++ b/vector/src/main/res/layout/item_suggested_room.xml @@ -80,7 +80,7 @@ android:layout_marginEnd="8dp" android:maxWidth="@dimen/button_max_width" android:text="@string/join" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toTopOf="@id/inlineErrorText" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -102,6 +102,17 @@ app:barrierDirection="bottom" app:constraint_referenced_ids="roomAvatarBottomSpace" /> + + + app:layout_constraintTop_toBottomOf="@+id/inlineErrorText" /> diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 621ecb7aee..f792038c07 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -3403,4 +3403,5 @@ "Teammate spaces aren’t quite ready but you can still give them a try" "At the moment people might not be able to join any private rooms you make.\n\nWe’ll be improving this as part of the beta, but just wanted to let you know." + Sorry, an error occurred while trying to join: %s