Send failure verified user : add some comments and logs.

This commit is contained in:
ganfra 2024-09-16 15:22:40 +02:00
parent aeea99196b
commit be3ead0db9
4 changed files with 38 additions and 3 deletions

View file

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

View file

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

View file

@ -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,

View file

@ -350,7 +350,23 @@ interface MatrixRoom : Closeable {
*/
suspend fun clearComposerDraft(): Result<Unit>
/**
* 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<UserId, List<DeviceId>>, transactionId: TransactionId): Result<Unit>
/**
* 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<UserId>, transactionId: TransactionId): Result<Unit>
override fun close() = destroy()