From 9e63a3219c7f5f9ae5c6e0f725aad19d61ab326d Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 26 Feb 2020 12:19:32 +0100 Subject: [PATCH] Add Re-Request keys for fail to decrypt --- .../riotx/features/home/room/detail/RoomDetailAction.kt | 1 + .../features/home/room/detail/RoomDetailFragment.kt | 3 +++ .../features/home/room/detail/RoomDetailViewModel.kt | 9 +++++++++ .../room/detail/timeline/action/EventSharedAction.kt | 3 +++ .../detail/timeline/action/MessageActionsViewModel.kt | 6 +++++- vector/src/main/res/values/strings.xml | 2 +- 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailAction.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailAction.kt index 2ef7b11b0e..3230686d58 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailAction.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailAction.kt @@ -71,4 +71,5 @@ sealed class RoomDetailAction : VectorViewModelAction { data class DeclineVerificationRequest(val transactionId: String, val otherUserId: String) : RoomDetailAction() data class RequestVerification(val userId: String) : RoomDetailAction() data class ResumeVerification(val transactionId: String, val otherUserId: String?) : RoomDetailAction() + data class ReRequestKeys(val eventId: String) : RoomDetailAction() } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index f83adaf8a7..ac16ee348d 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -1236,6 +1236,9 @@ class RoomDetailFragment @Inject constructor( is EventSharedAction.OnUrlLongClicked -> { onUrlLongClicked(action.url) } + is EventSharedAction.ReRequestKey -> { + roomDetailViewModel.handle(RoomDetailAction.ReRequestKeys(action.eventId)) + } else -> { Toast.makeText(context, "Action $action is not implemented yet", Toast.LENGTH_LONG).show() } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index f7a6c09022..2ad90f073a 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -209,6 +209,7 @@ class RoomDetailViewModel @AssistedInject constructor( is RoomDetailAction.DeclineVerificationRequest -> handleDeclineVerification(action) is RoomDetailAction.RequestVerification -> handleRequestVerification(action) is RoomDetailAction.ResumeVerification -> handleResumeRequestVerification(action) + is RoomDetailAction.ReRequestKeys -> handleReRequestKeys(action) } } @@ -886,6 +887,14 @@ class RoomDetailViewModel @AssistedInject constructor( } } + private fun handleReRequestKeys(action: RoomDetailAction.ReRequestKeys) { + // Check if this request is still active and handled by me + room.getTimeLineEvent(action.eventId)?.let { + session.cryptoService().reRequestRoomKeyForEvent(it.root) + _viewEvents.post(RoomDetailViewEvents.ShowMessage(stringProvider.getString(R.string.e2e_re_request_encryption_key_dialog_content))) + } + } + private fun handleReplyToOptions(action: RoomDetailAction.ReplyToOptions) { room.sendOptionsReply(action.eventId, action.optionIndex, action.optionValue) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/EventSharedAction.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/EventSharedAction.kt index b9e2ab2093..00fc1f22c6 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/EventSharedAction.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/EventSharedAction.kt @@ -102,4 +102,7 @@ sealed class EventSharedAction(@StringRes val titleRes: Int, // An url in the event preview has been long clicked data class OnUrlLongClicked(val url: String) : EventSharedAction(0, 0) + + data class ReRequestKey(val eventId: String) : + EventSharedAction(R.string.e2e_re_request_encryption_key, R.drawable.key_small) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index 1fe1db27d7..f1e9dc5bee 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -271,9 +271,13 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted } } + if (timelineEvent.isEncrypted() && timelineEvent.root.mCryptoError != null) { + add(EventSharedAction.ReRequestKey(timelineEvent.eventId)) + } + if (vectorPreferences.developerMode()) { add(EventSharedAction.ViewSource(timelineEvent.root.toContentStringWithIndent())) - if (timelineEvent.isEncrypted()) { + if (timelineEvent.isEncrypted() && timelineEvent.root.mxDecryptionResult != null) { val decryptedContent = timelineEvent.root.toClearContentStringWithIndent() ?: stringProvider.getString(R.string.encryption_information_decryption_error) add(EventSharedAction.ViewDecryptedSource(decryptedContent)) diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index f0c3bdc23d..76bcfe7290 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -301,7 +301,7 @@ You need to log back in to generate end-to-end encryption keys for this session and submit the public key to your homeserver.\nThis is a once off.\nSorry for the inconvenience. - Re-request encryption keys from your other sessions. + Re-request encryption keys from your other sessions. Key request sent.