Skip to content

Commit 781a477

Browse files
authored
Merge pull request #5292 from vector-im/feature/mna/4319-dm-space-members-list
#4319: Fix DM navigation in member profile screen
2 parents 9cc3564 + 96f041a commit 781a477

File tree

9 files changed

+28
-22
lines changed

9 files changed

+28
-22
lines changed

changelog.d/4319.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Open direct message screen when clicking on DM button in the space members list

vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailAction.kt

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ sealed class RoomDetailAction : VectorViewModelAction {
9292

9393
data class UpdateJoinJitsiCallStatus(val conferenceEvent: ConferenceEvent) : RoomDetailAction()
9494

95-
data class OpenOrCreateDm(val userId: String) : RoomDetailAction()
9695
data class JumpToReadReceipt(val userId: String) : RoomDetailAction()
9796
object QuickActionInvitePeople : RoomDetailAction()
9897
object QuickActionSetAvatar : RoomDetailAction()

vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailPendingAction.kt

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package im.vector.app.features.home.room.detail
1818

1919
sealed class RoomDetailPendingAction {
20-
data class OpenOrCreateDm(val userId: String) : RoomDetailPendingAction()
2120
data class JumpToReadReceipt(val userId: String) : RoomDetailPendingAction()
2221
data class MentionUser(val userId: String) : RoomDetailPendingAction()
2322
data class OpenRoom(val roomId: String, val closeCurrentRoom: Boolean = false) : RoomDetailPendingAction()

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt

-2
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,6 @@ class TimelineFragment @Inject constructor(
12471247
timelineViewModel.handle(RoomDetailAction.JumpToReadReceipt(roomDetailPendingAction.userId))
12481248
is RoomDetailPendingAction.MentionUser ->
12491249
insertUserDisplayNameInTextEditor(roomDetailPendingAction.userId)
1250-
is RoomDetailPendingAction.OpenOrCreateDm ->
1251-
timelineViewModel.handle(RoomDetailAction.OpenOrCreateDm(roomDetailPendingAction.userId))
12521250
is RoomDetailPendingAction.OpenRoom ->
12531251
handleOpenRoom(RoomDetailViewEvents.OpenRoom(roomDetailPendingAction.roomId, roomDetailPendingAction.closeCurrentRoom))
12541252
}.exhaustive

vector/src/main/java/im/vector/app/features/home/room/detail/TimelineViewModel.kt

+1-16
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ class TimelineViewModel @AssistedInject constructor(
417417
is RoomDetailAction.RemoveWidget -> handleDeleteWidget(action.widgetId)
418418
is RoomDetailAction.EnsureNativeWidgetAllowed -> handleCheckWidgetAllowed(action)
419419
is RoomDetailAction.CancelSend -> handleCancel(action)
420-
is RoomDetailAction.OpenOrCreateDm -> handleOpenOrCreateDm(action)
421420
is RoomDetailAction.JumpToReadReceipt -> handleJumpToReadReceipt(action)
422421
RoomDetailAction.QuickActionInvitePeople -> handleInvitePeople()
423422
RoomDetailAction.QuickActionSetAvatar -> handleQuickSetAvatar()
@@ -497,20 +496,6 @@ class TimelineViewModel @AssistedInject constructor(
497496
_viewEvents.post(RoomDetailViewEvents.OpenSetRoomAvatarDialog)
498497
}
499498

500-
private fun handleOpenOrCreateDm(action: RoomDetailAction.OpenOrCreateDm) {
501-
viewModelScope.launch {
502-
val roomId = try {
503-
directRoomHelper.ensureDMExists(action.userId)
504-
} catch (failure: Throwable) {
505-
_viewEvents.post(RoomDetailViewEvents.ActionFailure(action, failure))
506-
return@launch
507-
}
508-
if (roomId != initialState.roomId) {
509-
_viewEvents.post(RoomDetailViewEvents.OpenRoom(roomId = roomId))
510-
}
511-
}
512-
}
513-
514499
private fun handleJumpToReadReceipt(action: RoomDetailAction.JumpToReadReceipt) {
515500
room.getUserReadReceipt(action.userId)
516501
?.let { handleNavigateToEvent(RoomDetailAction.NavigateToEvent(it, true)) }
@@ -810,7 +795,7 @@ class TimelineViewModel @AssistedInject constructor(
810795
notificationDrawerManager.updateEvents { it.clearMemberShipNotificationForRoom(initialState.roomId) }
811796
viewModelScope.launch {
812797
try {
813-
session.leaveRoom(room.roomId)
798+
session.leaveRoom(room.roomId)
814799
} catch (throwable: Throwable) {
815800
_viewEvents.post(RoomDetailViewEvents.Failure(throwable, showInDialog = true))
816801
}

vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileAction.kt

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ sealed class RoomMemberProfileAction : VectorViewModelAction {
2929
object ShareRoomMemberProfile : RoomMemberProfileAction()
3030
data class SetPowerLevel(val previousValue: Int, val newValue: Int, val askForValidation: Boolean) : RoomMemberProfileAction()
3131
data class SetUserColorOverride(val newColorSpec: String) : RoomMemberProfileAction()
32+
data class OpenOrCreateDm(val userId: String) : RoomMemberProfileAction()
3233
}

vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class RoomMemberProfileFragment @Inject constructor(
127127
is RoomMemberProfileViewEvents.ShareRoomMemberProfile -> handleShareRoomMemberProfile(it.permalink)
128128
is RoomMemberProfileViewEvents.ShowPowerLevelValidation -> handleShowPowerLevelAdminWarning(it)
129129
is RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning -> handleShowPowerLevelDemoteWarning(it)
130+
is RoomMemberProfileViewEvents.OpenRoom -> handleOpenRoom(it)
130131
is RoomMemberProfileViewEvents.OnKickActionSuccess -> Unit
131132
is RoomMemberProfileViewEvents.OnSetPowerLevelSuccess -> Unit
132133
is RoomMemberProfileViewEvents.OnBanActionSuccess -> Unit
@@ -142,6 +143,10 @@ class RoomMemberProfileFragment @Inject constructor(
142143
headerViews.memberProfileIdView.copyOnLongClick()
143144
}
144145

146+
private fun handleOpenRoom(event: RoomMemberProfileViewEvents.OpenRoom) {
147+
navigator.openRoom(requireContext(), event.roomId, null)
148+
}
149+
145150
private fun handleShowPowerLevelDemoteWarning(event: RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning) {
146151
EditPowerLevelDialogs.showDemoteWarning(requireActivity()) {
147152
viewModel.handle(RoomMemberProfileAction.SetPowerLevel(event.currentValue, event.newValue, false))
@@ -297,8 +302,7 @@ class RoomMemberProfileFragment @Inject constructor(
297302
}
298303

299304
override fun onOpenDmClicked() {
300-
roomDetailPendingActionStore.data = RoomDetailPendingAction.OpenOrCreateDm(fragmentArgs.userId)
301-
vectorBaseActivity.finish()
305+
viewModel.handle(RoomMemberProfileAction.OpenOrCreateDm(fragmentArgs.userId))
302306
}
303307

304308
override fun onJumpToReadReceiptClicked() {

vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewEvents.kt

+1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ sealed class RoomMemberProfileViewEvents : VectorViewEvents {
3939
) : RoomMemberProfileViewEvents()
4040

4141
data class ShareRoomMemberProfile(val permalink: String) : RoomMemberProfileViewEvents()
42+
data class OpenRoom(val roomId: String) : RoomMemberProfileViewEvents()
4243
}

vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt

+18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import im.vector.app.core.extensions.exhaustive
3232
import im.vector.app.core.mvrx.runCatchingToAsync
3333
import im.vector.app.core.platform.VectorViewModel
3434
import im.vector.app.core.resources.StringProvider
35+
import im.vector.app.features.createdirect.DirectRoomHelper
3536
import im.vector.app.features.displayname.getBestName
3637
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
3738
import im.vector.app.features.powerlevel.PowerLevelsFlowFactory
@@ -66,6 +67,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
6667
@Assisted private val initialState: RoomMemberProfileViewState,
6768
private val stringProvider: StringProvider,
6869
private val matrixItemColorProvider: MatrixItemColorProvider,
70+
private val directRoomHelper: DirectRoomHelper,
6971
private val session: Session
7072
) : VectorViewModel<RoomMemberProfileViewState, RoomMemberProfileAction, RoomMemberProfileViewEvents>(initialState) {
7173

@@ -167,9 +169,25 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
167169
is RoomMemberProfileAction.KickUser -> handleKickAction(action)
168170
RoomMemberProfileAction.InviteUser -> handleInviteAction()
169171
is RoomMemberProfileAction.SetUserColorOverride -> handleSetUserColorOverride(action)
172+
is RoomMemberProfileAction.OpenOrCreateDm -> handleOpenOrCreateDm(action)
170173
}.exhaustive
171174
}
172175

176+
private fun handleOpenOrCreateDm(action: RoomMemberProfileAction.OpenOrCreateDm) {
177+
viewModelScope.launch {
178+
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
179+
val roomId = try {
180+
directRoomHelper.ensureDMExists(action.userId)
181+
} catch (failure: Throwable) {
182+
_viewEvents.post(RoomMemberProfileViewEvents.Failure(failure))
183+
return@launch
184+
}
185+
if (roomId != initialState.roomId) {
186+
_viewEvents.post(RoomMemberProfileViewEvents.OpenRoom(roomId = roomId))
187+
}
188+
}
189+
}
190+
173191
private fun handleSetUserColorOverride(action: RoomMemberProfileAction.SetUserColorOverride) {
174192
val newOverrideColorSpecs = session.accountDataService()
175193
.getUserAccountDataEvent(UserAccountDataTypes.TYPE_OVERRIDE_COLORS)

0 commit comments

Comments
 (0)