mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-14 11:05:32 -04:00
refactor(sdk): compute push actions before creating a decrypted TimelineEvent
This reduces the number of callers to `set_push_actions()`, which should be minimally used.
This commit is contained in:
committed by
Stefan Ceriu
parent
c48a2d68d1
commit
c6ed2d1963
@@ -337,23 +337,17 @@ impl Decryptor for (matrix_sdk_base::crypto::OlmMachine, ruma::OwnedRoomId) {
|
||||
let decryption_settings =
|
||||
DecryptionSettings { sender_device_trust_requirement: TrustRequirement::Untrusted };
|
||||
|
||||
let mut timeline_event = match olm_machine
|
||||
match olm_machine
|
||||
.try_decrypt_room_event(raw.cast_ref(), room_id, &decryption_settings)
|
||||
.await?
|
||||
{
|
||||
RoomEventDecryptionResult::Decrypted(decrypted) => {
|
||||
TimelineEvent::from_decrypted(decrypted, None)
|
||||
let push_actions = push_ctx.map(|push_ctx| push_ctx.for_event(&decrypted.event));
|
||||
Ok(TimelineEvent::from_decrypted(decrypted, push_actions))
|
||||
}
|
||||
RoomEventDecryptionResult::UnableToDecrypt(utd_info) => {
|
||||
TimelineEvent::new_utd_event(raw.clone(), utd_info)
|
||||
Ok(TimelineEvent::new_utd_event(raw.clone(), utd_info))
|
||||
}
|
||||
};
|
||||
|
||||
// Fill the push actions here, to mimic what `Room::decrypt_event` does.
|
||||
if let Some(push_ctx) = push_ctx {
|
||||
timeline_event.set_push_actions(push_ctx.for_event(timeline_event.raw()));
|
||||
}
|
||||
|
||||
Ok(timeline_event)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1502,28 +1502,22 @@ impl Room {
|
||||
sender_device_trust_requirement: self.client.base_client().decryption_trust_requirement,
|
||||
};
|
||||
|
||||
let mut event: TimelineEvent = match machine
|
||||
match machine
|
||||
.try_decrypt_room_event(event.cast_ref(), self.inner.room_id(), &decryption_settings)
|
||||
.await?
|
||||
{
|
||||
RoomEventDecryptionResult::Decrypted(decrypted) => {
|
||||
// Note: the push actions are set just afterwards.
|
||||
TimelineEvent::from_decrypted(decrypted, None)
|
||||
let push_actions = push_ctx.map(|push_ctx| push_ctx.for_event(&decrypted.event));
|
||||
Ok(TimelineEvent::from_decrypted(decrypted, push_actions))
|
||||
}
|
||||
RoomEventDecryptionResult::UnableToDecrypt(utd_info) => {
|
||||
self.client
|
||||
.encryption()
|
||||
.backups()
|
||||
.maybe_download_room_key(self.room_id().to_owned(), event.clone());
|
||||
TimelineEvent::new_utd_event(event.clone().cast(), utd_info)
|
||||
Ok(TimelineEvent::new_utd_event(event.clone().cast(), utd_info))
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(push_ctx) = push_ctx {
|
||||
event.set_push_actions(push_ctx.for_event(event.raw()));
|
||||
}
|
||||
|
||||
Ok(event)
|
||||
}
|
||||
|
||||
/// Fetches the [`EncryptionInfo`] for the supplied session_id.
|
||||
|
||||
Reference in New Issue
Block a user