From 3c6efd673e43fc8ba2da67a8728f9da29052fe43 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 7 Sep 2022 11:58:47 +0200 Subject: [PATCH 1/2] Allows you to open an invite by clicking the invite cell --- .../home/room/list/home/invites/InvitesAction.kt | 1 + .../home/room/list/home/invites/InvitesFragment.kt | 14 ++++++++++---- .../room/list/home/invites/InvitesViewEvents.kt | 6 +++++- .../room/list/home/invites/InvitesViewModel.kt | 12 +++++++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesAction.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesAction.kt index ed6ed23c9d..d96e0f01de 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesAction.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesAction.kt @@ -20,6 +20,7 @@ import im.vector.app.core.platform.VectorViewModelAction import org.matrix.android.sdk.api.session.room.model.RoomSummary sealed class InvitesAction : VectorViewModelAction { + data class SelectRoom(val roomSummary: RoomSummary) : InvitesAction() data class AcceptInvitation(val roomSummary: RoomSummary) : InvitesAction() data class RejectInvitation(val roomSummary: RoomSummary) : InvitesAction() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesFragment.kt index f557483289..0dbc1b8f34 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesFragment.kt @@ -66,7 +66,7 @@ class InvitesFragment : VectorBaseFragment(), RoomListLi viewModel.observeViewEvents { when (it) { is InvitesViewEvents.Failure -> showFailure(it.throwable) - is InvitesViewEvents.OpenRoom -> handleOpenRoom(it.roomSummary, it.shouldCloseInviteView) + is InvitesViewEvents.OpenRoom -> handleOpenRoom(it.roomSummary, it.shouldCloseInviteView, it.isInviteAlreadySelected) } } @@ -94,11 +94,15 @@ class InvitesFragment : VectorBaseFragment(), RoomListLi }.launchIn(viewLifecycleOwner.lifecycleScope) } - private fun handleOpenRoom(roomSummary: RoomSummary, shouldCloseInviteView: Boolean) { + private fun handleOpenRoom( + roomSummary: RoomSummary, + shouldCloseInviteView: Boolean, + isInviteAlreadyAccepted: Boolean, + ) { navigator.openRoom( context = requireActivity(), roomId = roomSummary.roomId, - isInviteAlreadyAccepted = true, + isInviteAlreadyAccepted = isInviteAlreadyAccepted, trigger = ViewRoom.Trigger.RoomList // #6508 ) if (shouldCloseInviteView) { @@ -120,7 +124,9 @@ class InvitesFragment : VectorBaseFragment(), RoomListLi override fun onSuggestedRoomClicked(room: SpaceChildInfo) = Unit - override fun onRoomClicked(room: RoomSummary) = Unit + override fun onRoomClicked(room: RoomSummary) { + viewModel.handle(InvitesAction.SelectRoom(room)) + } override fun onRoomLongClicked(room: RoomSummary): Boolean = false } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewEvents.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewEvents.kt index 21310592a4..69749b8c48 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewEvents.kt @@ -21,5 +21,9 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary sealed class InvitesViewEvents : VectorViewEvents { data class Failure(val throwable: Throwable) : InvitesViewEvents() - data class OpenRoom(val roomSummary: RoomSummary, val shouldCloseInviteView: Boolean) : InvitesViewEvents() + data class OpenRoom( + val roomSummary: RoomSummary, + val shouldCloseInviteView: Boolean, + val isInviteAlreadySelected: Boolean, + ) : InvitesViewEvents() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewModel.kt index b8034d2364..eec6512c81 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewModel.kt @@ -28,6 +28,7 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.resources.DrawableProvider import im.vector.app.core.resources.StringProvider +import im.vector.app.features.home.room.list.home.HomeRoomListViewEvents import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.catch @@ -76,11 +77,20 @@ class InvitesViewModel @AssistedInject constructor( override fun handle(action: InvitesAction) { when (action) { + is InvitesAction.SelectRoom -> handleSelectRoom(action) is InvitesAction.AcceptInvitation -> handleAcceptInvitation(action) is InvitesAction.RejectInvitation -> handleRejectInvitation(action) } } + private fun handleSelectRoom(action: InvitesAction.SelectRoom) { + _viewEvents.post(InvitesViewEvents.OpenRoom( + roomSummary = action.roomSummary, + shouldCloseInviteView = false, + isInviteAlreadySelected = false, + )) + } + private fun handleRejectInvitation(action: InvitesAction.RejectInvitation) = withState { state -> val roomId = action.roomSummary.roomId val roomMembershipChange = state.roomMembershipChanges[roomId] @@ -129,7 +139,7 @@ class InvitesViewModel @AssistedInject constructor( ) } - _viewEvents.post(InvitesViewEvents.OpenRoom(action.roomSummary, shouldCloseInviteView)) + _viewEvents.post(InvitesViewEvents.OpenRoom(action.roomSummary, shouldCloseInviteView, isInviteAlreadySelected = true)) } private fun observeInvites() { From 4a31dc403fa774b295f62fd62ec2d37989616751 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 7 Sep 2022 14:03:48 +0200 Subject: [PATCH 2/2] Removes unused import --- .../app/features/home/room/list/home/invites/InvitesViewModel.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewModel.kt index eec6512c81..8ef7c2bfef 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/invites/InvitesViewModel.kt @@ -28,7 +28,6 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.resources.DrawableProvider import im.vector.app.core.resources.StringProvider -import im.vector.app.features.home.room.list.home.HomeRoomListViewEvents import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.catch