Skip to content

Commit cced512

Browse files
gnunicornbnjbvr
authored andcommitted
Keep the raw notification event around for further processing
1 parent 06359b1 commit cced512

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

crates/matrix-sdk-ui/src/notification_client.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl NotificationClient {
452452
}
453453

454454
Ok(NotificationStatus::Event(
455-
NotificationItem::new(&room, &raw_event, push_actions.as_deref(), Vec::new()).await?,
455+
NotificationItem::new(&room, raw_event, push_actions.as_deref(), Vec::new()).await?,
456456
))
457457
}
458458

@@ -501,7 +501,7 @@ impl NotificationClient {
501501
Ok(Some(
502502
NotificationItem::new(
503503
&room,
504-
&RawNotificationEvent::Timeline(timeline_event.event.cast()),
504+
RawNotificationEvent::Timeline(timeline_event.event.cast()),
505505
timeline_event.push_actions.as_deref(),
506506
state_events,
507507
)
@@ -573,14 +573,26 @@ impl NotificationClientBuilder {
573573
}
574574
}
575575

576-
enum RawNotificationEvent {
576+
/// The Notification event as it was fetched from remote for the
577+
/// given `event_id`, represented as Raw but decrypted, thus only
578+
/// whether it is an invite or regular Timeline event has been
579+
/// determined.
580+
#[derive(Debug)]
581+
pub enum RawNotificationEvent {
582+
/// The raw event for a timeline event
577583
Timeline(Raw<AnySyncTimelineEvent>),
584+
/// The notification contains an invitation with the given
585+
/// StrippedRoomMemberEvent (in raw here)
578586
Invite(Raw<StrippedRoomMemberEvent>),
579587
}
580588

589+
/// The deserialized Event as it was fetched from remote for the
590+
/// given `event_id` and after decryption (if possible).
581591
#[derive(Debug)]
582592
pub enum NotificationEvent {
593+
/// The Notification was for a TimelineEvent
583594
Timeline(AnySyncTimelineEvent),
595+
/// The Notification is an invite with the given stripped room event data
584596
Invite(StrippedRoomMemberEvent),
585597
}
586598

@@ -599,6 +611,9 @@ pub struct NotificationItem {
599611
/// Underlying Ruma event.
600612
pub event: NotificationEvent,
601613

614+
/// The raw of the underlying event.
615+
pub raw_event: RawNotificationEvent,
616+
602617
/// Display name of the sender.
603618
pub sender_display_name: Option<String>,
604619
/// Avatar URL of the sender.
@@ -630,11 +645,11 @@ pub struct NotificationItem {
630645
impl NotificationItem {
631646
async fn new(
632647
room: &Room,
633-
raw_event: &RawNotificationEvent,
648+
raw_event: RawNotificationEvent,
634649
push_actions: Option<&[Action]>,
635650
state_events: Vec<Raw<AnyStateEvent>>,
636651
) -> Result<Self, Error> {
637-
let event = match raw_event {
652+
let event = match &raw_event {
638653
RawNotificationEvent::Timeline(raw_event) => {
639654
let mut event = raw_event.deserialize().map_err(|_| Error::InvalidRumaEvent)?;
640655
if let AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
@@ -694,6 +709,7 @@ impl NotificationItem {
694709

695710
let item = NotificationItem {
696711
event,
712+
raw_event,
697713
sender_display_name,
698714
sender_avatar_url,
699715
is_sender_name_ambiguous,

0 commit comments

Comments
 (0)