Iterate on shield mapping and rendering
Also handle click on the timeline and information displayed on long click.
This commit is contained in:
parent
5d10b1fe85
commit
faf1e7da9f
24 changed files with 399 additions and 245 deletions
|
|
@ -16,12 +16,32 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.timeline.item.event
|
||||
|
||||
data class MessageShield(
|
||||
val message: String,
|
||||
val color: ShieldColor,
|
||||
)
|
||||
import androidx.compose.runtime.Immutable
|
||||
|
||||
enum class ShieldColor {
|
||||
RED,
|
||||
GREY
|
||||
@Immutable
|
||||
sealed interface MessageShield {
|
||||
/** Not enough information available to check the authenticity.*/
|
||||
data class AuthenticityNotGuaranteed(val isCritical: Boolean) : MessageShield
|
||||
|
||||
/** The sending device isn't yet known by the Client.*/
|
||||
data class UnknownDevice(val isCritical: Boolean) : MessageShield
|
||||
|
||||
/** The sending device hasn't been verified by the sender.*/
|
||||
data class UnsignedDevice(val isCritical: Boolean) : MessageShield
|
||||
|
||||
/** The sender hasn't been verified by the Client's user.*/
|
||||
data class UnverifiedIdentity(val isCritical: Boolean) : MessageShield
|
||||
|
||||
/** An unencrypted event in an encrypted room.*/
|
||||
data class SentInClear(val isCritical: Boolean) : MessageShield
|
||||
}
|
||||
|
||||
fun MessageShield.isCritical(): Boolean {
|
||||
return when (this) {
|
||||
is MessageShield.AuthenticityNotGuaranteed -> isCritical
|
||||
is MessageShield.UnknownDevice -> isCritical
|
||||
is MessageShield.UnsignedDevice -> isCritical
|
||||
is MessageShield.UnverifiedIdentity -> isCritical
|
||||
is MessageShield.SentInClear -> isCritical
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@ import io.element.android.libraries.matrix.api.timeline.item.event.MessageShield
|
|||
import io.element.android.libraries.matrix.api.timeline.item.event.ProfileTimelineDetails
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.ReactionSender
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.Receipt
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.ShieldColor
|
||||
import io.element.android.libraries.matrix.api.timeline.item.event.TimelineItemEventOrigin
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import org.matrix.rustcomponents.sdk.Reaction
|
||||
import org.matrix.rustcomponents.sdk.ShieldState
|
||||
import uniffi.matrix_sdk_common.ShieldStateCode
|
||||
import org.matrix.rustcomponents.sdk.EventSendState as RustEventSendState
|
||||
import org.matrix.rustcomponents.sdk.EventTimelineItem as RustEventTimelineItem
|
||||
import org.matrix.rustcomponents.sdk.EventTimelineItemDebugInfo as RustEventTimelineItemDebugInfo
|
||||
|
|
@ -135,10 +135,22 @@ private fun RustEventItemOrigin.map(): TimelineItemEventOrigin {
|
|||
}
|
||||
|
||||
private fun ShieldState?.map(): MessageShield? {
|
||||
return when (this) {
|
||||
is ShieldState.Grey -> MessageShield(message = this.message, color = ShieldColor.GREY)
|
||||
is ShieldState.Red -> MessageShield(message = this.message, color = ShieldColor.RED)
|
||||
this ?: return null
|
||||
val shieldStateCode = when (this) {
|
||||
is ShieldState.Grey -> code
|
||||
is ShieldState.Red -> code
|
||||
ShieldState.None -> null
|
||||
} ?: return null
|
||||
val isCritical = when (this) {
|
||||
ShieldState.None,
|
||||
null -> null
|
||||
is ShieldState.Grey -> false
|
||||
is ShieldState.Red -> true
|
||||
}
|
||||
return when (shieldStateCode) {
|
||||
ShieldStateCode.AUTHENTICITY_NOT_GUARANTEED -> MessageShield.AuthenticityNotGuaranteed(isCritical)
|
||||
ShieldStateCode.UNKNOWN_DEVICE -> MessageShield.UnknownDevice(isCritical)
|
||||
ShieldStateCode.UNSIGNED_DEVICE -> MessageShield.UnsignedDevice(isCritical)
|
||||
ShieldStateCode.UNVERIFIED_IDENTITY -> MessageShield.UnverifiedIdentity(isCritical)
|
||||
ShieldStateCode.SENT_IN_CLEAR -> MessageShield.SentInClear(isCritical)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue