mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
Room member profile: Add action to create (or open) a DM (#2310)
This commit is contained in:
parent
f127a75e38
commit
4433436416
12 changed files with 61 additions and 17 deletions
|
@ -12,6 +12,7 @@ Improvements 🙌:
|
|||
- Use Hardware keyboard enter to send message (use shift-enter for new line) (#1881, #1440)
|
||||
- Edit and remove icons are now visible on image attachment preview screen (#2294)
|
||||
- Room profile: BigImageViewerActivity now only display the image. Use the room setting to change or delete the room Avatar
|
||||
- Room member profile: Add action to create (or open) a DM (#2310)
|
||||
|
||||
Bugfix 🐛:
|
||||
- Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252)
|
||||
|
|
|
@ -285,14 +285,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
|||
|
||||
fun createDM(alice: Session, bob: Session): String {
|
||||
val roomId = mTestHelper.doSync<String> {
|
||||
alice.createRoom(
|
||||
CreateRoomParams().apply {
|
||||
invitedUserIds.add(bob.myUserId)
|
||||
setDirectMessage()
|
||||
enableEncryptionIfInvitedUsersSupportIt = true
|
||||
},
|
||||
it
|
||||
)
|
||||
alice.createDirectRoom(bob.myUserId, it)
|
||||
}
|
||||
|
||||
mTestHelper.waitWithLatch { latch ->
|
||||
|
|
|
@ -35,6 +35,22 @@ interface RoomService {
|
|||
fun createRoom(createRoomParams: CreateRoomParams,
|
||||
callback: MatrixCallback<String>): Cancelable
|
||||
|
||||
/**
|
||||
* Create a direct room asynchronously. This is a facility method to create a direct room with the necessary parameters
|
||||
*/
|
||||
fun createDirectRoom(otherUserId: String,
|
||||
callback: MatrixCallback<String>): Cancelable {
|
||||
return createRoom(
|
||||
CreateRoomParams()
|
||||
.apply {
|
||||
invitedUserIds.add(otherUserId)
|
||||
setDirectMessage()
|
||||
enableEncryptionIfInvitedUsersSupportIt = true
|
||||
},
|
||||
callback
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a room by id
|
||||
* @param roomIdOrAlias the roomId or the room alias of the room to join
|
||||
|
|
|
@ -49,7 +49,6 @@ import org.matrix.android.sdk.api.session.crypto.verification.VerificationServic
|
|||
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTransaction
|
||||
import org.matrix.android.sdk.api.session.crypto.verification.VerificationTxState
|
||||
import org.matrix.android.sdk.api.session.events.model.LocalEcho
|
||||
import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
|
||||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
import org.matrix.android.sdk.internal.crypto.crosssigning.fromBase64
|
||||
|
@ -245,14 +244,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
|
|||
pendingRequest = Loading()
|
||||
)
|
||||
}
|
||||
val roomParams = CreateRoomParams()
|
||||
.apply {
|
||||
invitedUserIds.add(otherUserId)
|
||||
setDirectMessage()
|
||||
enableEncryptionIfInvitedUsersSupportIt = true
|
||||
}
|
||||
|
||||
session.createRoom(roomParams, object : MatrixCallback<String> {
|
||||
session.createDirectRoom(otherUserId, object : MatrixCallback<String> {
|
||||
override fun onSuccess(data: String) {
|
||||
setState {
|
||||
copy(
|
||||
|
|
|
@ -88,5 +88,6 @@ sealed class RoomDetailAction : VectorViewModelAction {
|
|||
val userJustAccepted: Boolean,
|
||||
val grantedEvents: RoomDetailViewEvents) : RoomDetailAction()
|
||||
|
||||
data class OpenOrCreateDm(val userId: String) : RoomDetailAction()
|
||||
data class JumpToReadReceipt(val userId: String) : RoomDetailAction()
|
||||
}
|
||||
|
|
|
@ -363,6 +363,7 @@ class RoomDetailFragment @Inject constructor(
|
|||
RoomDetailViewEvents.ShowWaitingView -> vectorBaseActivity.showWaitingView()
|
||||
RoomDetailViewEvents.HideWaitingView -> vectorBaseActivity.hideWaitingView()
|
||||
is RoomDetailViewEvents.RequestNativeWidgetPermission -> requestNativeWidgetPermission(it)
|
||||
is RoomDetailViewEvents.OpenRoom -> handleOpenRoom(it)
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
|
@ -371,6 +372,10 @@ class RoomDetailFragment @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleOpenRoom(openRoom: RoomDetailViewEvents.OpenRoom) {
|
||||
navigator.openRoom(requireContext(), openRoom.roomId, null)
|
||||
}
|
||||
|
||||
private fun requestNativeWidgetPermission(it: RoomDetailViewEvents.RequestNativeWidgetPermission) {
|
||||
val tag = RoomWidgetPermissionBottomSheet::class.java.name
|
||||
val dFrag = childFragmentManager.findFragmentByTag(tag) as? RoomWidgetPermissionBottomSheet
|
||||
|
@ -886,6 +891,8 @@ class RoomDetailFragment @Inject constructor(
|
|||
roomDetailViewModel.handle(RoomDetailAction.JumpToReadReceipt(roomDetailPendingAction.userId))
|
||||
is RoomDetailPendingAction.MentionUser ->
|
||||
insertUserDisplayNameInTextEditor(roomDetailPendingAction.userId)
|
||||
is RoomDetailPendingAction.OpenOrCreateDm ->
|
||||
roomDetailViewModel.handle(RoomDetailAction.OpenOrCreateDm(roomDetailPendingAction.userId))
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package im.vector.app.features.home.room.detail
|
||||
|
||||
sealed class RoomDetailPendingAction {
|
||||
data class OpenOrCreateDm(val userId: String) : RoomDetailPendingAction()
|
||||
data class JumpToReadReceipt(val userId: String) : RoomDetailPendingAction()
|
||||
data class MentionUser(val userId: String) : RoomDetailPendingAction()
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ sealed class RoomDetailViewEvents : VectorViewEvents {
|
|||
data class ShowInfoOkDialog(val message: String) : RoomDetailViewEvents()
|
||||
data class ShowE2EErrorMessage(val withHeldCode: WithHeldCode?) : RoomDetailViewEvents()
|
||||
|
||||
data class OpenRoom(val roomId: String) : RoomDetailViewEvents()
|
||||
|
||||
data class NavigateToEvent(val eventId: String) : RoomDetailViewEvents()
|
||||
data class JoinJitsiConference(val widget: Widget, val withVideo: Boolean) : RoomDetailViewEvents()
|
||||
|
||||
|
|
|
@ -273,10 +273,26 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
is RoomDetailAction.RemoveWidget -> handleDeleteWidget(action.widgetId)
|
||||
is RoomDetailAction.EnsureNativeWidgetAllowed -> handleCheckWidgetAllowed(action)
|
||||
is RoomDetailAction.CancelSend -> handleCancel(action)
|
||||
is RoomDetailAction.OpenOrCreateDm -> handleOpenOrCreateDm(action)
|
||||
is RoomDetailAction.JumpToReadReceipt -> handleJumpToReadReceipt(action)
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
private fun handleOpenOrCreateDm(action: RoomDetailAction.OpenOrCreateDm) {
|
||||
val existingDm = session.getExistingDirectRoomWithUser(action.userId)
|
||||
if (existingDm == null) {
|
||||
// First create a direct room
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val roomId = awaitCallback<String> {
|
||||
session.createDirectRoom(action.userId, it)
|
||||
}
|
||||
_viewEvents.post(RoomDetailViewEvents.OpenRoom(roomId))
|
||||
}
|
||||
} else {
|
||||
_viewEvents.post(RoomDetailViewEvents.OpenRoom(existingDm.roomId))
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleJumpToReadReceipt(action: RoomDetailAction.JumpToReadReceipt) {
|
||||
room.getUserReadReceipt(action.userId)
|
||||
?.let { handleNavigateToEvent(RoomDetailAction.NavigateToEvent(it, true)) }
|
||||
|
|
|
@ -45,6 +45,7 @@ class RoomMemberProfileController @Inject constructor(
|
|||
fun onTapVerify()
|
||||
fun onShowDeviceList()
|
||||
fun onShowDeviceListNoCrossSigning()
|
||||
fun onOpenDmClicked()
|
||||
fun onJumpToReadReceiptClicked()
|
||||
fun onMentionClicked()
|
||||
fun onEditPowerLevel(currentRole: Role)
|
||||
|
@ -173,6 +174,14 @@ class RoomMemberProfileController @Inject constructor(
|
|||
|
||||
buildProfileSection(stringProvider.getString(R.string.room_profile_section_more))
|
||||
|
||||
buildProfileAction(
|
||||
id = "direct",
|
||||
editable = false,
|
||||
title = stringProvider.getString(R.string.room_member_open_or_create_dm),
|
||||
dividerColor = dividerColor,
|
||||
action = { callback?.onOpenDmClicked() }
|
||||
)
|
||||
|
||||
if (state.hasReadReceipt) {
|
||||
buildProfileAction(
|
||||
id = "read_receipt",
|
||||
|
|
|
@ -278,6 +278,11 @@ class RoomMemberProfileFragment @Inject constructor(
|
|||
DeviceListBottomSheet.newInstance(it.userId).show(parentFragmentManager, "DEV_LIST")
|
||||
}
|
||||
|
||||
override fun onOpenDmClicked() {
|
||||
roomDetailPendingActionStore.data = RoomDetailPendingAction.OpenOrCreateDm(fragmentArgs.userId)
|
||||
vectorBaseActivity.finish()
|
||||
}
|
||||
|
||||
override fun onJumpToReadReceiptClicked() {
|
||||
roomDetailPendingActionStore.data = RoomDetailPendingAction.JumpToReadReceipt(fragmentArgs.userId)
|
||||
vectorBaseActivity.finish()
|
||||
|
|
|
@ -2167,6 +2167,7 @@
|
|||
<string name="room_member_power_level_default_in">Default in %1$s</string>
|
||||
<string name="room_member_power_level_custom_in">Custom (%1$d) in %2$s</string>
|
||||
|
||||
<string name="room_member_open_or_create_dm">Direct message</string>
|
||||
<string name="room_member_jump_to_read_receipt">Jump to read receipt</string>
|
||||
|
||||
<string name="rendering_event_error_type_of_event_not_handled">"Element does not handle events of type '%1$s'"</string>
|
||||
|
|
Loading…
Reference in a new issue