Allows you to open an invite by clicking the invite cell

This commit is contained in:
ericdecanini 2022-09-07 11:58:47 +02:00
parent da88b37ec7
commit 3c6efd673e
4 changed files with 27 additions and 6 deletions

View File

@ -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()
}

View File

@ -66,7 +66,7 @@ class InvitesFragment : VectorBaseFragment<FragmentInvitesBinding>(), 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<FragmentInvitesBinding>(), 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<FragmentInvitesBinding>(), 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
}

View File

@ -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()
}

View File

@ -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() {