Skip to content

Commit 1caa606

Browse files
committed
refactor(timeline): move is_utd() to TimelineItemContent
It's unusual to have the method on the parent type when the field type could also hold the method. In fact, this was the only bool getter inspecting the timeline's content, so let's move the method next to as its siblings, for consistency, and let's spell it out fully for clarity.
1 parent 3fbf159 commit 1caa606

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ impl TimelineItemContent {
325325
as_variant!(self, Self::UnableToDecrypt)
326326
}
327327

328+
/// Check whether this item's content is a
329+
/// [`UnableToDecrypt`][Self::UnableToDecrypt].
330+
pub fn is_unable_to_decrypt(&self) -> bool {
331+
matches!(self, Self::UnableToDecrypt(_))
332+
}
333+
328334
// These constructors could also be `From` implementations, but that would
329335
// allow users to call them directly, which should not be supported
330336
pub(crate) fn message(

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@ impl EventTimelineItem {
233233
matches!(self.kind, EventTimelineItemKind::Remote(_))
234234
}
235235

236-
/// Check whether this item's content is UTD (unable to decrypt).
237-
pub fn is_utd(&self) -> bool {
238-
matches!(self.content(), TimelineItemContent::UnableToDecrypt(_))
239-
}
240-
241236
/// Get the `LocalEventTimelineItem` if `self` is `Local`.
242237
pub(super) fn as_local(&self) -> Option<&LocalEventTimelineItem> {
243238
as_variant!(&self.kind, EventTimelineItemKind::Local(local_event_item) => local_event_item)

crates/matrix-sdk-ui/src/timeline/tests/encryption.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ async fn test_retry_decryption_updates_response() {
748748
assert_eq!(reply_details.event_id, original_event_id);
749749

750750
let replied_to = as_variant!(&reply_details.event, TimelineDetails::Ready).unwrap();
751-
assert!(replied_to.content.as_unable_to_decrypt().is_some());
751+
assert!(replied_to.content.is_unable_to_decrypt());
752752
}
753753

754754
// Import a room key backup.

testing/matrix-sdk-integration-testing/src/tests/sliding_sync/room.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ async fn test_delayed_invite_response_and_sent_message_decryption() {
920920
continue;
921921
};
922922

923-
if event.is_utd() {
923+
if event.content().is_unable_to_decrypt() {
924924
info!("Observed UTD for {}", event.event_id().unwrap());
925925
}
926926

0 commit comments

Comments
 (0)