Skip to content

Commit 366bf4b

Browse files
committed
refactor(crypto): Use the session ID stored in RemoteEventTimelineItem to decide what to redecrypt
In future commits this will allow us to redecrypt more messages when we get an update, not just UTDs. This should help us update warnings on messages when we get new information e.g. about whether a device is verified.
1 parent 8c77e01 commit 366bf4b

File tree

1 file changed

+12
-19
lines changed
  • crates/matrix-sdk-ui/src/timeline/controller

1 file changed

+12
-19
lines changed

crates/matrix-sdk-ui/src/timeline/controller/mod.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,6 @@ impl<P: RoomDataProvider> TimelineController<P> {
10491049
decryptor: impl Decryptor,
10501050
session_ids: Option<BTreeSet<String>>,
10511051
) {
1052-
use super::EncryptedMessage;
1053-
10541052
let mut state = self.state.clone().write_owned().await;
10551053

10561054
let should_retry = move |session_id: &str| {
@@ -1065,15 +1063,12 @@ impl<P: RoomDataProvider> TimelineController<P> {
10651063
.items
10661064
.iter()
10671065
.enumerate()
1068-
.filter_map(|(idx, item)| match item.as_event()?.content().as_unable_to_decrypt()? {
1069-
EncryptedMessage::MegolmV1AesSha2 { session_id, .. }
1070-
if should_retry(session_id) =>
1071-
{
1066+
.filter_map(|(idx, item)| {
1067+
if should_retry(item.as_event()?.as_remote()?.session_id.as_ref()?) {
10721068
Some(idx)
1069+
} else {
1070+
None
10731071
}
1074-
EncryptedMessage::MegolmV1AesSha2 { .. }
1075-
| EncryptedMessage::OlmV1Curve25519AesSha2 { .. }
1076-
| EncryptedMessage::Unknown => None,
10771072
})
10781073
.collect();
10791074

@@ -1096,16 +1091,14 @@ impl<P: RoomDataProvider> TimelineController<P> {
10961091
async move {
10971092
let event_item = item.as_event()?;
10981093

1099-
let session_id = match event_item.content().as_unable_to_decrypt()? {
1100-
EncryptedMessage::MegolmV1AesSha2 { session_id, .. }
1101-
if should_retry(session_id) =>
1102-
{
1103-
session_id
1104-
}
1105-
EncryptedMessage::MegolmV1AesSha2 { .. }
1106-
| EncryptedMessage::OlmV1Curve25519AesSha2 { .. }
1107-
| EncryptedMessage::Unknown => return None,
1108-
};
1094+
let session_id =
1095+
event_item.as_remote()?.session_id.as_ref().and_then(|session_id| {
1096+
if should_retry(session_id) {
1097+
Some(session_id)
1098+
} else {
1099+
None
1100+
}
1101+
});
11091102

11101103
tracing::Span::current().record("session_id", session_id);
11111104

0 commit comments

Comments
 (0)