mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-08 07:56:55 -04:00
feat(timeline): Expose shield state for EventTimelineItem (#3679)
This commit is contained in:
@@ -24,6 +24,7 @@ use matrix_sdk::{
|
||||
AttachmentConfig, AttachmentInfo, BaseAudioInfo, BaseFileInfo, BaseImageInfo,
|
||||
BaseThumbnailInfo, BaseVideoInfo, Thumbnail,
|
||||
},
|
||||
deserialized_responses::ShieldState as RustShieldState,
|
||||
Error,
|
||||
};
|
||||
use matrix_sdk_ui::timeline::{
|
||||
@@ -922,6 +923,30 @@ impl From<&matrix_sdk_ui::timeline::EventSendState> for EventSendState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Recommended decorations for decrypted messages, representing the message's
|
||||
/// authenticity properties.
|
||||
#[derive(uniffi::Enum)]
|
||||
pub enum ShieldState {
|
||||
/// A red shield with a tooltip containing the associated message should be
|
||||
/// presented.
|
||||
Red { message: String },
|
||||
/// A grey shield with a tooltip containing the associated message should be
|
||||
/// presented.
|
||||
Grey { message: String },
|
||||
/// No shield should be presented.
|
||||
None,
|
||||
}
|
||||
|
||||
impl From<RustShieldState> for ShieldState {
|
||||
fn from(value: RustShieldState) -> Self {
|
||||
match value {
|
||||
RustShieldState::Red { message } => Self::Red { message: message.to_owned() },
|
||||
RustShieldState::Grey { message } => Self::Grey { message: message.to_owned() },
|
||||
RustShieldState::None => Self::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct EventTimelineItem(pub(crate) matrix_sdk_ui::timeline::EventTimelineItem);
|
||||
|
||||
@@ -1008,6 +1033,12 @@ impl EventTimelineItem {
|
||||
pub fn can_be_replied_to(&self) -> bool {
|
||||
self.0.can_be_replied_to()
|
||||
}
|
||||
|
||||
/// Gets the [`ShieldState`] which can be used to decorate messages in the
|
||||
/// recommended way.
|
||||
pub fn get_shield(&self, strict: bool) -> Option<ShieldState> {
|
||||
self.0.get_shield(strict).map(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(uniffi::Record)]
|
||||
|
||||
@@ -16,7 +16,10 @@ use std::sync::Arc;
|
||||
|
||||
use as_variant::as_variant;
|
||||
use indexmap::IndexMap;
|
||||
use matrix_sdk::{deserialized_responses::EncryptionInfo, Client, Error};
|
||||
use matrix_sdk::{
|
||||
deserialized_responses::{EncryptionInfo, ShieldState},
|
||||
Client, Error,
|
||||
};
|
||||
use matrix_sdk_base::{deserialized_responses::SyncTimelineEvent, latest_event::LatestEvent};
|
||||
use once_cell::sync::Lazy;
|
||||
use ruma::{
|
||||
@@ -335,6 +338,18 @@ impl EventTimelineItem {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the [`ShieldState`] which can be used to decorate messages in the
|
||||
/// recommended way.
|
||||
pub fn get_shield(&self, strict: bool) -> Option<ShieldState> {
|
||||
self.encryption_info().map(|info| {
|
||||
if strict {
|
||||
info.verification_state.to_shield_state_strict()
|
||||
} else {
|
||||
info.verification_state.to_shield_state_lax()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Check whether this item can be replied to.
|
||||
pub fn can_be_replied_to(&self) -> bool {
|
||||
// This must be in sync with the early returns of `Timeline::send_reply`
|
||||
|
||||
Reference in New Issue
Block a user