Skip to content

Commit

Permalink
feat(bindings): Add TimelineItemContent::as_unable_to_decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Nov 3, 2022
1 parent 642565f commit 39937d2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions bindings/matrix-sdk-ffi/src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,25 @@ impl TimelineItemContent {
unwrap_or_clone_arc_into_variant!(self, .0, C::Message(msg) => Arc::new(Message(msg)))
}

pub fn as_unable_to_decrypt(&self) -> Option<EncryptedMessage> {
use matrix_sdk::room::timeline::{EncryptedMessage as E, TimelineItemContent as C};

match &self.0 {
C::UnableToDecrypt(utd) => Some(match utd {
E::OlmV1Curve25519AesSha2 { sender_key } => {
let sender_key = sender_key.clone();
EncryptedMessage::OlmV1Curve25519AesSha2 { sender_key }
}
E::MegolmV1AesSha2 { session_id, .. } => {
let session_id = session_id.clone();
EncryptedMessage::MegolmV1AesSha2 { session_id }
}
E::Unknown => EncryptedMessage::Unknown,
}),
_ => None,
}
}

pub fn is_redacted_message(&self) -> bool {
use matrix_sdk::room::timeline::TimelineItemContent as C;
matches!(self.0, C::RedactedMessage)
Expand Down Expand Up @@ -374,6 +393,21 @@ impl From<&matrix_sdk::ruma::events::room::ImageInfo> for ImageInfo {
}
}

#[derive(Clone, uniffi::Enum)]
pub enum EncryptedMessage {
OlmV1Curve25519AesSha2 {
/// The Curve25519 key of the sender.
sender_key: String,
},
// Other fields not included because UniFFI doesn't have the concept of
// deprecated fields right now.
MegolmV1AesSha2 {
/// The ID of the session used to encrypt the message.
session_id: String,
},
Unknown,
}

#[derive(Clone, uniffi::Record)]
pub struct Reaction {
pub key: String,
Expand Down

0 comments on commit 39937d2

Please sign in to comment.