Skip to content

Commit be3ead0

Browse files
committed
Send failure verified user : add some comments and logs.
1 parent aeea991 commit be3ead0

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/ResolveVerifiedUserSendFailureView.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private fun VerifiedUserSendFailure.title(): String {
118118
id = CommonStrings.screen_resolve_send_failure_changed_identity_title,
119119
userDisplayName
120120
)
121-
VerifiedUserSendFailure.None -> ""
121+
VerifiedUserSendFailure.None -> error("This method should never be called for this state")
122122
}
123123
}
124124

@@ -134,7 +134,7 @@ private fun VerifiedUserSendFailure.subtitle(): String {
134134
id = CommonStrings.screen_resolve_send_failure_changed_identity_subtitle,
135135
userDisplayName
136136
)
137-
VerifiedUserSendFailure.None -> ""
137+
VerifiedUserSendFailure.None -> error("This method should never be called for this state")
138138
}
139139
}
140140

@@ -143,7 +143,7 @@ private fun VerifiedUserSendFailure.resolveAction(): String {
143143
return when (this) {
144144
is VerifiedUserSendFailure.UnsignedDevice -> stringResource(id = CommonStrings.screen_resolve_send_failure_unsigned_device_primary_button_title)
145145
is VerifiedUserSendFailure.ChangedIdentity -> stringResource(id = CommonStrings.screen_resolve_send_failure_changed_identity_primary_button_title)
146-
VerifiedUserSendFailure.None -> ""
146+
VerifiedUserSendFailure.None -> error("This method should never be called for this state")
147147
}
148148
}
149149

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureIterator.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package io.element.android.features.messages.impl.crypto.sendfailure.resolve
99

1010
import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState
11+
import timber.log.Timber
1112

1213
/**
1314
* Iterator for [LocalEventSendState.Failed.VerifiedUser]
@@ -30,6 +31,12 @@ class UnsignedDeviceSendFailureIterator(
3031
) : VerifiedUserSendFailureIterator {
3132
private val iterator = failure.devices.iterator()
3233

34+
init {
35+
if (!hasNext()) {
36+
Timber.w("Got $failure without any devices, shouldn't happen.")
37+
}
38+
}
39+
3340
override fun hasNext(): Boolean {
3441
return iterator.hasNext()
3542
}
@@ -47,6 +54,12 @@ class ChangedIdentitySendFailureIterator(
4754
) : VerifiedUserSendFailureIterator {
4855
private val iterator = failure.users.iterator()
4956

57+
init {
58+
if (!hasNext()) {
59+
Timber.w("Got $failure without any users, shouldn't happen.")
60+
}
61+
}
62+
5063
override fun hasNext(): Boolean {
5164
return iterator.hasNext()
5265
}

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/crypto/sendfailure/resolve/VerifiedUserSendFailureResolver.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import io.element.android.libraries.matrix.api.room.MatrixRoom
1313
import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState
1414
import timber.log.Timber
1515

16+
/**
17+
* This class is responsible for resolving and resending a failed message sent to a verified user.
18+
* It also allow to resend the message without resolving the failure, for example if the user has in the meantime verified their device again.
19+
* It's using the [VerifiedUserSendFailureIterator] to iterate over the different failures (ie. the different users concerned by the failure).
20+
* This way, the user can resolve and resend the message for each user concerned, one by one.
21+
*/
1622
class VerifiedUserSendFailureResolver(
1723
private val room: MatrixRoom,
1824
private val transactionId: TransactionId,

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,23 @@ interface MatrixRoom : Closeable {
350350
*/
351351
suspend fun clearComposerDraft(): Result<Unit>
352352

353+
/**
354+
* Ignore the local trust for the given devices and resend messages that failed to send because said devices are unverified.
355+
*
356+
* @param devices The map of users identifiers to device identifiers received in the error
357+
* @param transactionId The send queue transaction identifier of the local echo the send error applies to.
358+
*
359+
*/
353360
suspend fun ignoreDeviceTrustAndResend(devices: Map<UserId, List<DeviceId>>, transactionId: TransactionId): Result<Unit>
361+
362+
/**
363+
* Remove verification requirements for the given users and
364+
* resend messages that failed to send because their identities were no longer verified.
365+
*
366+
* @param userIds The list of users identifiers received in the error.
367+
* @param transactionId The send queue transaction identifier of the local echo the send error applies to.
368+
*
369+
*/
354370
suspend fun withdrawVerificationAndResend(userIds: List<UserId>, transactionId: TransactionId): Result<Unit>
355371

356372
override fun close() = destroy()

0 commit comments

Comments
 (0)