Skip to content

Commit

Permalink
refactor(ui): add unable_to_decrypt_info to EncryptedEvent
Browse files Browse the repository at this point in the history
When we construct a new
`matrix_sdk_ui::timeline::event_item::EncryptedMessage`, include the
`unable_to_decrypt_info`.
  • Loading branch information
richvdh committed Oct 17, 2024
1 parent 4cd5883 commit bf420bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
7 changes: 5 additions & 2 deletions crates/matrix-sdk-ui/src/timeline/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,14 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
}
},

TimelineEventKind::UnableToDecrypt { content, .. } => {
TimelineEventKind::UnableToDecrypt { content, unable_to_decrypt_info } => {
// TODO: Handle replacements if the replaced event is also UTD
let raw_event = self.ctx.flow.raw_event();
let cause = UtdCause::determine(raw_event);
self.add_item(TimelineItemContent::unable_to_decrypt(content, cause), None);
self.add_item(
TimelineItemContent::unable_to_decrypt(content, unable_to_decrypt_info, cause),
None,
);

// Let the hook know that we ran into an unable-to-decrypt that is added to the
// timeline.
Expand Down
35 changes: 30 additions & 5 deletions crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use std::sync::Arc;
use as_variant::as_variant;
use imbl::Vector;
use matrix_sdk::crypto::types::events::UtdCause;
use matrix_sdk_base::latest_event::{is_suitable_for_latest_event, PossibleLatestEvent};
use matrix_sdk_base::{
deserialized_responses::UnableToDecryptInfo,
latest_event::{is_suitable_for_latest_event, PossibleLatestEvent},
};
use ruma::{
events::{
call::{invite::SyncCallInviteEvent, notify::SyncCallNotifyEvent},
Expand Down Expand Up @@ -329,8 +332,16 @@ impl TimelineItemContent {
}
}

pub(crate) fn unable_to_decrypt(content: RoomEncryptedEventContent, cause: UtdCause) -> Self {
Self::UnableToDecrypt(EncryptedMessage::from_content(content, cause))
pub(crate) fn unable_to_decrypt(
content: RoomEncryptedEventContent,
unable_to_decrypt_info: UnableToDecryptInfo,
cause: UtdCause,
) -> Self {
Self::UnableToDecrypt(EncryptedMessage::from_content(
content,
unable_to_decrypt_info,
cause,
))
}

pub(crate) fn room_member(
Expand Down Expand Up @@ -437,8 +448,12 @@ pub enum EncryptedMessage {
device_id: OwnedDeviceId,

/// The ID of the session used to encrypt the message.
/// TODO: remove? it's the same as unable_to_decrypt_info.session_id
session_id: String,

/// Information on the decryption failure from the crypto crate.
unable_to_decrypt_info: UnableToDecryptInfo,

/// What we know about what caused this UTD. E.g. was this event sent
/// when we were not a member of this room?
cause: UtdCause,
Expand All @@ -448,7 +463,11 @@ pub enum EncryptedMessage {
}

impl EncryptedMessage {
fn from_content(content: RoomEncryptedEventContent, cause: UtdCause) -> Self {
fn from_content(
content: RoomEncryptedEventContent,
unable_to_decrypt_info: UnableToDecryptInfo,
cause: UtdCause,
) -> Self {
match content.scheme {
EncryptedEventScheme::OlmV1Curve25519AesSha2(s) => {
Self::OlmV1Curve25519AesSha2 { sender_key: s.sender_key }
Expand All @@ -457,7 +476,13 @@ impl EncryptedMessage {
EncryptedEventScheme::MegolmV1AesSha2(s) => {
let MegolmV1AesSha2Content { sender_key, device_id, session_id, .. } = s;

Self::MegolmV1AesSha2 { sender_key, device_id, session_id, cause }
Self::MegolmV1AesSha2 {
sender_key,
device_id,
session_id,
unable_to_decrypt_info,
cause,
}
}
_ => Self::Unknown,
}
Expand Down

0 comments on commit bf420bb

Please sign in to comment.