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 4dca3a4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
9 changes: 5 additions & 4 deletions bindings/matrix-sdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ mod uniffi_types {
SlidingSyncView, SlidingSyncViewBuilder, StoppableSpawn, UnreadNotificationsCount,
},
timeline::{
EmoteMessageContent, EventTimelineItem, FormattedBody, ImageInfo, ImageMessageContent,
InsertAtData, Message, MessageFormat, MessageType, NoticeMessageContent, Reaction,
TextMessageContent, ThumbnailInfo, TimelineChange, TimelineDiff, TimelineItem,
TimelineItemContent, TimelineKey, UpdateAtData, VirtualTimelineItem,
EmoteMessageContent, EncryptedMessage, EventTimelineItem, FormattedBody, ImageInfo,
ImageMessageContent, InsertAtData, Message, MessageFormat, MessageType,
NoticeMessageContent, Reaction, TextMessageContent, ThumbnailInfo, TimelineChange,
TimelineDiff, TimelineItem, TimelineItemContent, TimelineKey, UpdateAtData,
VirtualTimelineItem,
},
};
}
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 4dca3a4

Please sign in to comment.