From 6c29b5c6948afe924c549d6556bad45d002794de Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 16 Sep 2024 15:22:40 +0200 Subject: [PATCH] Send failure verified user : add some comments and logs. --- .../ResolveVerifiedUserSendFailureView.kt | 6 +++--- .../resolve/VerifiedUserSendFailureIterator.kt | 13 +++++++++++++ .../resolve/VerifiedUserSendFailureResolver.kt | 6 ++++++ .../libraries/matrix/api/room/MatrixRoom.kt | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/ResolveVerifiedUserSendFailureView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/ResolveVerifiedUserSendFailureView.kt index e0d964fa51..4c1d40cc87 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/ResolveVerifiedUserSendFailureView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/ResolveVerifiedUserSendFailureView.kt @@ -118,7 +118,7 @@ private fun VerifiedUserSendFailure.title(): String { id = CommonStrings.screen_resolve_send_failure_changed_identity_title, userDisplayName ) - VerifiedUserSendFailure.None -> "" + VerifiedUserSendFailure.None -> error("This method should never be called for this state") } } @@ -134,7 +134,7 @@ private fun VerifiedUserSendFailure.subtitle(): String { id = CommonStrings.screen_resolve_send_failure_changed_identity_subtitle, userDisplayName ) - VerifiedUserSendFailure.None -> "" + VerifiedUserSendFailure.None -> error("This method should never be called for this state") } } @@ -143,7 +143,7 @@ private fun VerifiedUserSendFailure.resolveAction(): String { return when (this) { is VerifiedUserSendFailure.UnsignedDevice -> stringResource(id = CommonStrings.screen_resolve_send_failure_unsigned_device_primary_button_title) is VerifiedUserSendFailure.ChangedIdentity -> stringResource(id = CommonStrings.screen_resolve_send_failure_changed_identity_primary_button_title) - VerifiedUserSendFailure.None -> "" + VerifiedUserSendFailure.None -> error("This method should never be called for this state") } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureIterator.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureIterator.kt index ccdcfb509b..8b438808ff 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureIterator.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureIterator.kt @@ -8,6 +8,7 @@ package io.element.android.features.messages.impl.crypto.sendfailure.resolve import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState +import timber.log.Timber /** * Iterator for [LocalEventSendState.Failed.VerifiedUser] @@ -30,6 +31,12 @@ class UnsignedDeviceSendFailureIterator( ) : VerifiedUserSendFailureIterator { private val iterator = failure.devices.iterator() + init { + if (!hasNext()) { + Timber.w("Got $failure without any devices, shouldn't happen.") + } + } + override fun hasNext(): Boolean { return iterator.hasNext() } @@ -47,6 +54,12 @@ class ChangedIdentitySendFailureIterator( ) : VerifiedUserSendFailureIterator { private val iterator = failure.users.iterator() + init { + if (!hasNext()) { + Timber.w("Got $failure without any users, shouldn't happen.") + } + } + override fun hasNext(): Boolean { return iterator.hasNext() } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureResolver.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureResolver.kt index 0f6049b11f..be775ed122 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureResolver.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureResolver.kt @@ -13,6 +13,12 @@ import io.element.android.libraries.matrix.api.room.MatrixRoom import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState import timber.log.Timber +/** + * This class is responsible for resolving and resending a failed message sent to a verified user. + * It also allow to resend the message without resolving the failure, for example if the user has in the meantime verified their device again. + * It's using the [VerifiedUserSendFailureIterator] to iterate over the different failures (ie. the different users concerned by the failure). + * This way, the user can resolve and resend the message for each user concerned, one by one. + */ class VerifiedUserSendFailureResolver( private val room: MatrixRoom, private val transactionId: TransactionId, diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt index 1936b9f60c..d266b45d35 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt @@ -350,7 +350,23 @@ interface MatrixRoom : Closeable { */ suspend fun clearComposerDraft(): Result + /** + * Ignore the local trust for the given devices and resend messages that failed to send because said devices are unverified. + * + * @param devices The map of users identifiers to device identifiers received in the error + * @param transactionId The send queue transaction identifier of the local echo the send error applies to. + * + */ suspend fun ignoreDeviceTrustAndResend(devices: Map>, transactionId: TransactionId): Result + + /** + * Remove verification requirements for the given users and + * resend messages that failed to send because their identities were no longer verified. + * + * @param userIds The list of users identifiers received in the error. + * @param transactionId The send queue transaction identifier of the local echo the send error applies to. + * + */ suspend fun withdrawVerificationAndResend(userIds: List, transactionId: TransactionId): Result override fun close() = destroy()