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:
Benjamin Bouvier
2025-06-04 12:22:21 +02:00
committed by Stefan Ceriu
parent c48a2d68d1
commit c6ed2d1963
2 changed files with 8 additions and 20 deletions

View File

@@ -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)
}
}

View File

@@ -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.