Rust sdk : refactor LocalSendState to use the new failure states as iOS does

This commit is contained in:
ganfra
2024-08-27 17:45:22 +02:00
parent 57c6abfe47
commit 18959a930f
9 changed files with 57 additions and 38 deletions

View File

@@ -18,13 +18,27 @@ package io.element.android.libraries.matrix.api.timeline.item.event
import androidx.compose.runtime.Immutable
import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.core.UserId
@Immutable
sealed interface LocalEventSendState {
data object NotSentYet : LocalEventSendState
sealed class SendingFailed(open val error: String) : LocalEventSendState {
data class Recoverable(override val error: String) : SendingFailed(error)
data class Unrecoverable(override val error: String) : SendingFailed(error)
data object Sending : LocalEventSendState
sealed interface Failed : LocalEventSendState {
data class Unknown(val error: String) : Failed
data class VerifiedUserHasUnsignedDevice(
/**
* The unsigned devices belonging to verified users. A map from user ID
* to a list of device IDs.
*/
val devices: Map<UserId, List<String>>
) : Failed
data class VerifiedUserChangedIdentity(
/**
* The users that were previously verified but are no longer.
*/
val users: List<UserId>
) : Failed
}
data class Sent(
val eventId: EventId

View File

@@ -81,15 +81,23 @@ fun RustProfileDetails.map(): ProfileTimelineDetails {
fun RustEventSendState?.map(): LocalEventSendState? {
return when (this) {
null -> null
RustEventSendState.NotSentYet -> LocalEventSendState.NotSentYet
RustEventSendState.NotSentYet -> LocalEventSendState.Sending
is RustEventSendState.SendingFailed -> {
if (this.isRecoverable) {
LocalEventSendState.SendingFailed.Recoverable(this.error)
if (isRecoverable) {
LocalEventSendState.Sending
} else {
LocalEventSendState.SendingFailed.Unrecoverable(this.error)
LocalEventSendState.Failed.Unknown(error)
}
}
is RustEventSendState.Sent -> LocalEventSendState.Sent(EventId(eventId))
is RustEventSendState.VerifiedUserChangedIdentity -> {
LocalEventSendState.Failed.VerifiedUserChangedIdentity(users.map { UserId(it) })
}
is RustEventSendState.VerifiedUserHasUnsignedDevice -> {
LocalEventSendState.Failed.VerifiedUserHasUnsignedDevice(
devices = devices.mapKeys { UserId(it.key) }
)
}
}
}