diff --git a/bindings/matrix-sdk-ffi/src/event.rs b/bindings/matrix-sdk-ffi/src/event.rs index 6eb2c4c21..9209d0e9b 100644 --- a/bindings/matrix-sdk-ffi/src/event.rs +++ b/bindings/matrix-sdk-ffi/src/event.rs @@ -1,3 +1,5 @@ +use std::ops::Deref; + use anyhow::{bail, Context}; use matrix_sdk::IdParseError; use matrix_sdk_ui::timeline::TimelineEventItemId; @@ -22,7 +24,7 @@ use crate::{ }; #[derive(uniffi::Object)] -pub struct TimelineEvent(pub(crate) AnySyncTimelineEvent); +pub struct TimelineEvent(pub(crate) Box); #[matrix_sdk_ffi_macros::export] impl TimelineEvent { @@ -39,7 +41,7 @@ impl TimelineEvent { } pub fn event_type(&self) -> Result { - let event_type = match &self.0 { + let event_type = match self.0.deref() { AnySyncTimelineEvent::MessageLike(event) => { TimelineEventType::MessageLike { content: event.clone().try_into()? } } @@ -53,7 +55,7 @@ impl TimelineEvent { impl From for TimelineEvent { fn from(event: AnyTimelineEvent) -> Self { - Self(event.into()) + Self(Box::new(event.into())) } } diff --git a/crates/matrix-sdk-ui/src/notification_client.rs b/crates/matrix-sdk-ui/src/notification_client.rs index bfd452a44..e8ab6baf2 100644 --- a/crates/matrix-sdk-ui/src/notification_client.rs +++ b/crates/matrix-sdk-ui/src/notification_client.rs @@ -835,9 +835,9 @@ pub enum RawNotificationEvent { #[derive(Debug)] pub enum NotificationEvent { /// The Notification was for a TimelineEvent - Timeline(AnySyncTimelineEvent), + Timeline(Box), /// The Notification is an invite with the given stripped room event data - Invite(StrippedRoomMemberEvent), + Invite(Box), } impl NotificationEvent { @@ -851,7 +851,10 @@ impl NotificationEvent { /// Returns the root event id of the thread the notification event is in, if /// any. fn thread_id(&self) -> Option { - let NotificationEvent::Timeline(AnySyncTimelineEvent::MessageLike(event)) = &self else { + let NotificationEvent::Timeline(sync_timeline_event) = &self else { + return None; + }; + let AnySyncTimelineEvent::MessageLike(event) = sync_timeline_event.as_ref() else { return None; }; let content = event.original_content()?; @@ -923,11 +926,11 @@ impl NotificationItem { { ev.content.sanitize(DEFAULT_SANITIZER_MODE, RemoveReplyFallback::Yes); } - NotificationEvent::Timeline(event) + NotificationEvent::Timeline(Box::new(event)) } - RawNotificationEvent::Invite(raw_event) => NotificationEvent::Invite( + RawNotificationEvent::Invite(raw_event) => NotificationEvent::Invite(Box::new( raw_event.deserialize().map_err(|_| Error::InvalidRumaEvent)?, - ), + )), }; let sender = match room.state() { diff --git a/testing/matrix-sdk-integration-testing/src/tests/nse.rs b/testing/matrix-sdk-integration-testing/src/tests/nse.rs index 40b4a9222..a04304087 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/nse.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/nse.rs @@ -389,17 +389,17 @@ impl NotificationClientWrapper { .expect("Failed to get_notification"); if let Some(item) = item { - if let NotificationEvent::Timeline(AnySyncTimelineEvent::MessageLike(e)) = - item.event - { - if let AnyMessageLikeEventContent::RoomMessage(c) = - e.original_content().expect("Empty original content") - { - self.events - .lock() - .unwrap() - .push((event_info.0.clone(), c.body().to_owned())); - return; + if let NotificationEvent::Timeline(sync_timeline_event) = item.event { + if let AnySyncTimelineEvent::MessageLike(event) = sync_timeline_event.as_ref() { + if let AnyMessageLikeEventContent::RoomMessage(event_content) = + event.original_content().expect("Empty original content") + { + self.events + .lock() + .unwrap() + .push((event_info.0.clone(), event_content.body().to_owned())); + return; + } } } }; diff --git a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs index ff1924ede..ace0b9188 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs @@ -183,19 +183,25 @@ async fn test_notification() -> Result<()> { assert_matches!( notification.event, NotificationEvent::Timeline( - matrix_sdk::ruma::events::AnySyncTimelineEvent::MessageLike( - matrix_sdk::ruma::events::AnySyncMessageLikeEvent::RoomMessage( - SyncMessageLikeEvent::Original(event) - ) - ) + sync_timeline_event ) => { - assert_matches!(event.content.msgtype, - matrix_sdk::ruma::events::room::message::MessageType::Text(text) => { - assert_eq!(text.body, "Hello world!"); - }); - } + assert_matches!( + sync_timeline_event.as_ref(), + matrix_sdk::ruma::events::AnySyncTimelineEvent::MessageLike( + matrix_sdk::ruma::events::AnySyncMessageLikeEvent::RoomMessage( + SyncMessageLikeEvent::Original(event) + ) + ) => { + assert_matches!( + &event.content.msgtype, + matrix_sdk::ruma::events::room::message::MessageType::Text(text) => { + assert_eq!(text.body, "Hello world!"); + } + ); + } + ); + } ); - assert_eq!(notification.sender_display_name.as_deref(), Some(ALICE_NAME)); assert_eq!(notification.room_computed_display_name, ROOM_NAME); };