From 12f94a3fd2e5cd86beb6efaf576eab2195b8cb3b Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 2 Jul 2025 11:24:42 +0200 Subject: [PATCH] feat(ui): expose timestamp and identifier on EmbeddedEvent Signed-off-by: Johannes Marbach --- crates/matrix-sdk-ui/CHANGELOG.md | 2 ++ .../src/timeline/event_item/content/reply.rs | 17 ++++++++++++++--- .../tests/integration/timeline/replies.rs | 13 +++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk-ui/CHANGELOG.md b/crates/matrix-sdk-ui/CHANGELOG.md index f6dd811a7..bcdc179a9 100644 --- a/crates/matrix-sdk-ui/CHANGELOG.md +++ b/crates/matrix-sdk-ui/CHANGELOG.md @@ -11,6 +11,8 @@ All notable changes to this project will be documented in this file. - Add `NotificationItem::room_topic` to the `NotificationItem` struct, which contains the topic of the room. This is useful for displaying the room topic in notifications. ([#5300](https://github.com/matrix-org/matrix-rust-sdk/pull/5300)) +- Add `EmbeddedEvent::timestamp` and `EmbeddedEvent::identifier` which are already + available in regular timeline items. ([#5331](https://github.com/matrix-org/matrix-rust-sdk/pull/5331)) ## [0.12.0] - 2025-06-10 diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs index ad21d6fd0..fe4522c46 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use imbl::Vector; use matrix_sdk::deserialized_responses::TimelineEvent; -use ruma::{OwnedEventId, OwnedUserId}; +use ruma::{MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId}; use tracing::{debug, instrument, warn}; use super::TimelineItemContent; @@ -25,7 +25,7 @@ use crate::timeline::{ event_handler::TimelineAction, event_item::{EventTimelineItem, Profile, TimelineDetails}, traits::RoomDataProvider, - Error as TimelineError, TimelineItem, + Error as TimelineError, TimelineEventItemId, TimelineItem, }; /// Details about an event being replied to. @@ -68,6 +68,13 @@ pub struct EmbeddedEvent { pub sender: OwnedUserId, /// The profile of the sender of the related embedded event. pub sender_profile: TimelineDetails, + /// The timestamp of the event. + pub timestamp: MilliSecondsSinceUnixEpoch, + /// The unique identifier of this event. + /// + /// This is the transaction ID for a local echo that has not been sent and + /// the event ID for a local echo that has been sent or a remote event. + pub identifier: TimelineEventItemId, } impl EmbeddedEvent { @@ -77,6 +84,8 @@ impl EmbeddedEvent { content: timeline_item.content.clone(), sender: timeline_item.sender.clone(), sender_profile: timeline_item.sender_profile.clone(), + timestamp: timeline_item.timestamp, + identifier: timeline_item.identifier(), } } @@ -111,6 +120,8 @@ impl EmbeddedEvent { let thread_summary = None; let sender = event.sender().to_owned(); + let timestamp = event.origin_server_ts(); + let identifier = TimelineEventItemId::EventId(event.event_id().to_owned()); let action = TimelineAction::from_event( event, &raw_event, @@ -132,6 +143,6 @@ impl EmbeddedEvent { room_data_provider.profile_from_user_id(&sender).await, ); - Ok(Some(Self { content, sender, sender_profile })) + Ok(Some(Self { content, sender, sender_profile, timestamp, identifier })) } } diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs b/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs index affbc2219..70ce43e91 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/replies.rs @@ -14,7 +14,7 @@ use matrix_sdk_test::{ }; use matrix_sdk_ui::timeline::{ Error as TimelineError, EventSendState, MsgLikeContent, MsgLikeKind, RoomExt, TimelineDetails, - TimelineItemContent, + TimelineEventItemId, TimelineItemContent, }; use ruma::{ event_id, @@ -31,7 +31,7 @@ use ruma::{ sticker::{StickerEventContent, StickerMediaSource}, Mentions, }, - owned_event_id, owned_mxc_uri, room_id, + owned_event_id, owned_mxc_uri, room_id, MilliSecondsSinceUnixEpoch, UInt, }; use serde_json::json; use stream_assert::{assert_next_matches, assert_pending}; @@ -72,12 +72,15 @@ async fn test_in_reply_to_details() { // Add an event and a reply to that event to the timeline let eid1 = event_id!("$event1"); + let timestamp = MilliSecondsSinceUnixEpoch(UInt::new(1984).unwrap()); let f = EventFactory::new(); server .sync_room( &client, JoinedRoomBuilder::new(room_id) - .add_timeline_event(f.text_msg("hello").sender(*ALICE).event_id(eid1)) + .add_timeline_event( + f.text_msg("hello").sender(*ALICE).event_id(eid1).server_ts(timestamp), + ) .add_timeline_event(f.text_msg("hello to you too").reply_to(eid1).sender(*BOB)), ) .await; @@ -102,7 +105,9 @@ async fn test_in_reply_to_details() { ); let in_reply_to = in_reply_to.clone().unwrap(); assert_eq!(in_reply_to.event_id, eid1); - assert_matches!(in_reply_to.event, TimelineDetails::Ready(_)); + assert_let!(TimelineDetails::Ready(embedded) = in_reply_to.event); + assert_eq!(embedded.timestamp, timestamp); + assert_eq!(embedded.identifier, TimelineEventItemId::EventId(eid1.to_owned())); // Good old date divider. assert_let!(VectorDiff::PushFront { value: date_divider } = &timeline_updates[2]);