Skip to content

Commit 7962253

Browse files
committed
refactor(timeline): only use the publicly exposed content/sender/sender_profile on EmbeddedEvent
1 parent dd14df0 commit 7962253

File tree

9 files changed

+31
-49
lines changed

9 files changed

+31
-49
lines changed

bindings/matrix-sdk-ffi/src/timeline/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,9 @@ impl Timeline {
690690
Ok(Some(replied_to)) => Ok(Arc::new(InReplyToDetails::new(
691691
event_id_str,
692692
EmbeddedEventDetails::Ready {
693-
content: replied_to.content().clone().into(),
694-
sender: replied_to.sender().to_string(),
695-
sender_profile: replied_to.sender_profile().into(),
693+
content: replied_to.content.clone().into(),
694+
sender: replied_to.sender.to_string(),
695+
sender_profile: (&replied_to.sender_profile).into(),
696696
},
697697
))),
698698

@@ -1144,6 +1144,7 @@ pub enum ProfileDetails {
11441144
Error { message: String },
11451145
}
11461146

1147+
// TODO try to !use &
11471148
impl From<&TimelineDetails<Profile>> for ProfileDetails {
11481149
fn from(details: &TimelineDetails<Profile>) -> Self {
11491150
match details {

bindings/matrix-sdk-ffi/src/timeline/reply.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,11 @@ impl From<TimelineDetails<Box<EmbeddedEvent>>> for EmbeddedEventDetails {
5959
match event {
6060
TimelineDetails::Unavailable => EmbeddedEventDetails::Unavailable,
6161
TimelineDetails::Pending => EmbeddedEventDetails::Pending,
62-
TimelineDetails::Ready(event) => {
63-
let sender_profile = event.sender_profile().into();
64-
EmbeddedEventDetails::Ready {
65-
content: event.content.into(),
66-
sender: event.sender.to_string(),
67-
sender_profile,
68-
}
69-
}
62+
TimelineDetails::Ready(event) => EmbeddedEventDetails::Ready {
63+
content: event.content.into(),
64+
sender: event.sender.to_string(),
65+
sender_profile: (&event.sender_profile).into(),
66+
},
7067
TimelineDetails::Error(err) => EmbeddedEventDetails::Error { message: err.to_string() },
7168
}
7269
}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::sync::Arc;
1616

1717
use imbl::Vector;
1818
use matrix_sdk::deserialized_responses::{TimelineEvent, UnsignedEventLocation};
19-
use ruma::{OwnedEventId, OwnedUserId, UserId};
19+
use ruma::{OwnedEventId, OwnedUserId};
2020
use tracing::{debug, instrument, warn};
2121

2222
use super::TimelineItemContent;
@@ -71,22 +71,6 @@ pub struct EmbeddedEvent {
7171
}
7272

7373
impl EmbeddedEvent {
74-
// TODO: remove public getters
75-
/// Get the message of this event.
76-
pub fn content(&self) -> &TimelineItemContent {
77-
&self.content
78-
}
79-
80-
/// Get the sender of this event.
81-
pub fn sender(&self) -> &UserId {
82-
&self.sender
83-
}
84-
85-
/// Get the profile of the sender.
86-
pub fn sender_profile(&self) -> &TimelineDetails<Profile> {
87-
&self.sender_profile
88-
}
89-
9074
/// Create a [`EmbeddedEvent`] from a loaded event timeline item.
9175
pub fn from_timeline_item(timeline_item: &EventTimelineItem) -> Self {
9276
Self {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ async fn test_reply() {
419419
let in_reply_to = in_reply_to.clone().unwrap();
420420
assert_eq!(in_reply_to.event_id, first_event_id);
421421
assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event);
422-
assert_eq!(replied_to_event.sender(), *ALICE);
422+
assert_eq!(replied_to_event.sender, *ALICE);
423423
}
424424

425425
#[async_test]
@@ -461,7 +461,7 @@ async fn test_thread() {
461461
let in_reply_to = in_reply_to.clone().unwrap();
462462
assert_eq!(in_reply_to.event_id, first_event_id);
463463
assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event);
464-
assert_eq!(replied_to_event.sender(), *ALICE);
464+
assert_eq!(replied_to_event.sender, *ALICE);
465465
}
466466

467467
#[async_test]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ async fn test_retry_decryption_updates_response() {
873873
assert_eq!(reply_details.event_id, original_event_id);
874874

875875
let replied_to = as_variant!(&reply_details.event, TimelineDetails::Ready).unwrap();
876-
assert!(replied_to.content().is_unable_to_decrypt());
876+
assert!(replied_to.content.is_unable_to_decrypt());
877877
}
878878

879879
// Import a room key backup.
@@ -908,7 +908,7 @@ async fn test_retry_decryption_updates_response() {
908908
assert_eq!(reply_details.event_id, original_event_id);
909909

910910
let replied_to = as_variant!(&reply_details.event, TimelineDetails::Ready).unwrap();
911-
assert_eq!(replied_to.content().as_message().unwrap().body(), "It's a secret to everybody");
911+
assert_eq!(replied_to.content.as_message().unwrap().body(), "It's a secret to everybody");
912912
}
913913

914914
// The event itself is decrypted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async fn test_redact_replied_to_event() {
8080
let msglike = second_item.content().as_msglike().unwrap();
8181
let in_reply_to = msglike.in_reply_to.clone().unwrap();
8282
assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event);
83-
assert!(replied_to_event.content().is_message());
83+
assert!(replied_to_event.content.is_message());
8484

8585
timeline.handle_live_event(f.redaction(first_item.event_id().unwrap()).sender(&ALICE)).await;
8686

@@ -94,7 +94,7 @@ async fn test_redact_replied_to_event() {
9494
let msglike = second_item_again.content().as_msglike().unwrap();
9595
let in_reply_to = msglike.in_reply_to.clone().unwrap();
9696
assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event);
97-
assert!(replied_to_event.content().is_redacted());
97+
assert!(replied_to_event.content.is_redacted());
9898
}
9999

100100
#[async_test]

crates/matrix-sdk-ui/tests/integration/timeline/edit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ async fn test_edit_to_replied_updates_reply() {
462462
assert_eq!(in_reply_to.event_id, eid1);
463463

464464
assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event);
465-
assert_eq!(replied_to.content().as_message().unwrap().body(), "bonjour");
465+
assert_eq!(replied_to.content.as_message().unwrap().body(), "bonjour");
466466
});
467467

468468
assert_next_matches!(timeline_stream, VectorDiff::PushBack { value: reply_item } => {
@@ -474,7 +474,7 @@ async fn test_edit_to_replied_updates_reply() {
474474
assert_eq!(in_reply_to.event_id, eid1);
475475

476476
assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event);
477-
assert_eq!(replied_to.content().as_message().unwrap().body(), "bonjour");
477+
assert_eq!(replied_to.content.as_message().unwrap().body(), "bonjour");
478478
});
479479

480480
server.mock_room_send().ok(event_id!("$edit_event")).mock_once().mount().await;
@@ -509,7 +509,7 @@ async fn test_edit_to_replied_updates_reply() {
509509
let in_reply_to = msglike.in_reply_to.clone().unwrap();
510510
assert_eq!(in_reply_to.event_id, eid1);
511511
assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event);
512-
assert_eq!(replied_to.content().as_message().unwrap().body(), "hello world");
512+
assert_eq!(replied_to.content.as_message().unwrap().body(), "hello world");
513513
});
514514

515515
assert_next_matches!(timeline_stream, VectorDiff::Set { index: 2, value } => {
@@ -521,7 +521,7 @@ async fn test_edit_to_replied_updates_reply() {
521521
let in_reply_to = msglike.in_reply_to.clone().unwrap();
522522
assert_eq!(in_reply_to.event_id, eid1);
523523
assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event);
524-
assert_eq!(replied_to.content().as_message().unwrap().body(), "hello world");
524+
assert_eq!(replied_to.content.as_message().unwrap().body(), "hello world");
525525
});
526526

527527
sleep(Duration::from_millis(200)).await;

crates/matrix-sdk-ui/tests/integration/timeline/replies.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ async fn test_fetch_details_utd() {
349349
// The replied-to event is available, and is a UTD.
350350
let in_reply_to = in_reply_to.clone().unwrap();
351351
assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event);
352-
assert_eq!(replied_to.sender(), *ALICE);
352+
assert_eq!(replied_to.sender, *ALICE);
353353
assert_matches!(
354-
replied_to.content(),
354+
replied_to.content,
355355
TimelineItemContent::MsgLike(MsgLikeContent {
356356
kind: MsgLikeKind::UnableToDecrypt(_),
357357
..
@@ -461,8 +461,8 @@ async fn test_fetch_details_poll() {
461461
// The replied-to event is available, and is the poll.
462462
let in_reply_to = in_reply_to.clone().unwrap();
463463
assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event);
464-
assert_eq!(replied_to.sender(), *ALICE);
465-
assert_let!(Some(poll_state) = replied_to.content().as_poll());
464+
assert_eq!(replied_to.sender, *ALICE);
465+
assert_let!(Some(poll_state) = replied_to.content.as_poll());
466466
assert_eq!(
467467
poll_state.fallback_text().unwrap(),
468468
"What is the best color? A. Red, B. Blue, C. Green"
@@ -572,8 +572,8 @@ async fn test_fetch_details_sticker() {
572572
// The replied-to event is available, and is a sticker.
573573
let in_reply_to = in_reply_to.clone().unwrap();
574574
assert_let!(TimelineDetails::Ready(replied_to) = &in_reply_to.event);
575-
assert_eq!(replied_to.sender(), *ALICE);
576-
assert_let!(Some(sticker) = replied_to.content().as_sticker());
575+
assert_eq!(replied_to.sender, *ALICE);
576+
assert_let!(Some(sticker) = replied_to.content.as_sticker());
577577
assert_eq!(sticker.content().body, "sticker!");
578578
assert_matches!(&sticker.content().source, StickerMediaSource::Plain(src) => {
579579
assert_eq!(*src, media_src);
@@ -894,7 +894,7 @@ async fn test_send_reply_to_threaded() {
894894
assert_eq!(in_reply_to.event_id, event_id_1);
895895

896896
assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event);
897-
assert_eq!(replied_to_event.sender(), *BOB);
897+
assert_eq!(replied_to_event.sender, *BOB);
898898

899899
// Wait for remote echo.
900900
let diff = timeout(timeline_stream.next(), Duration::from_secs(1)).await.unwrap().unwrap();
@@ -910,7 +910,7 @@ async fn test_send_reply_to_threaded() {
910910
assert_eq!(in_reply_to.event_id, event_id_1);
911911

912912
assert_let!(TimelineDetails::Ready(replied_to_event) = &in_reply_to.event);
913-
assert_eq!(replied_to_event.sender(), *BOB);
913+
assert_eq!(replied_to_event.sender, *BOB);
914914
}
915915

916916
#[async_test]

crates/matrix-sdk-ui/tests/integration/timeline/thread.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ async fn test_new_thread_reply_causes_thread_summary() {
312312
// info.
313313
let replied_to_details = value.as_event().unwrap().content().in_reply_to().unwrap().event;
314314
assert_let!(TimelineDetails::Ready(replied_to_event) = replied_to_details);
315-
assert!(replied_to_event.content().thread_summary().is_none());
315+
assert!(replied_to_event.content.thread_summary().is_none());
316316

317317
// Since the replied-to item (the thread root) has been updated, all replies get
318318
// updated too, including the item we just pushed.
@@ -322,7 +322,7 @@ async fn test_new_thread_reply_causes_thread_summary() {
322322
let replied_to_details = value.as_event().unwrap().content().in_reply_to().unwrap().event;
323323
assert_let!(TimelineDetails::Ready(replied_to_event) = replied_to_details);
324324
// Spoiling a bit here…
325-
assert!(replied_to_event.content().thread_summary().is_some());
325+
assert!(replied_to_event.content.thread_summary().is_some());
326326

327327
// And finally, the thread root event receives a thread summary.
328328
assert_let!(VectorDiff::Set { index: 1, value } = &timeline_updates[2]);
@@ -378,7 +378,7 @@ async fn test_new_thread_reply_causes_thread_summary() {
378378
let replied_to_details = value.as_event().unwrap().content().in_reply_to().unwrap().event;
379379
assert_let!(TimelineDetails::Ready(replied_to_event) = replied_to_details);
380380
// Spoiling a bit here…
381-
assert_eq!(replied_to_event.content().thread_summary().unwrap().num_replies, 2);
381+
assert_eq!(replied_to_event.content.thread_summary().unwrap().num_replies, 2);
382382

383383
// Then, we receive an update for the thread root itself, which now has an
384384
// up-to-date thread summary.

0 commit comments

Comments
 (0)