Skip to content

Commit

Permalink
moar changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Sep 16, 2024
1 parent fcc4c7d commit e32ce30
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions crates/matrix-sdk-ui/src/notification_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ impl NotificationClient {
// notification, so we can figure out the full event and associated
// information.

let notification = Arc::new(Mutex::new(None));
let raw_notification = Arc::new(Mutex::new(None));

let cloned_notif = notification.clone();
let handler_raw_notification = raw_notification.clone();
let target_event_id = event_id.to_owned();

let timeline_event_handler =
Expand All @@ -312,7 +312,7 @@ impl NotificationClient {
if event_id == target_event_id {
// found it! There shouldn't be a previous event before, but if there
// is, that should be ok to just replace it.
*cloned_notif.lock().unwrap() =
*handler_raw_notification.lock().unwrap() =
Some(RawNotificationEvent::Timeline(raw));
}
}
Expand All @@ -325,9 +325,11 @@ impl NotificationClient {
}
});

let cloned_notif = notification.clone();
let raw_invite = Arc::new(Mutex::new(None));

let target_event_id = event_id.to_owned();
let user_id = self.client.user_id().unwrap().to_owned();
let handler_raw_invite = raw_invite.clone();
let stripped_member_handler =
self.client.add_event_handler(move |raw: Raw<StrippedRoomMemberEvent>| async move {
let deserialized = match raw.deserialize() {
Expand All @@ -344,7 +346,8 @@ impl NotificationClient {
if event_id == target_event_id {
// found it! There shouldn't be a previous event before, but if there
// is, that should be ok to just replace it.
*cloned_notif.lock().unwrap() = Some(RawNotificationEvent::Invite(raw));
*handler_raw_invite.lock().unwrap() =
Some(RawNotificationEvent::Invite(raw));
return;
}
}
Expand All @@ -361,11 +364,11 @@ impl NotificationClient {
if deserialized.content.membership == MembershipState::Invite
&& deserialized.state_key == user_id
{
// could be it! There shouldn't be a previous event before, but if there
// is, that should be ok to just replace it.
let mut notif = cloned_notif.lock().unwrap();
if notif.is_none() {
*notif = Some(RawNotificationEvent::Invite(raw));
// This could be it! Don't replace a previous event, though, as it might be
// more precise.
let mut invite = handler_raw_invite.lock().unwrap();
if invite.is_none() {
*invite = Some(RawNotificationEvent::Invite(raw));
}
}
});
Expand Down Expand Up @@ -420,7 +423,7 @@ impl NotificationClient {
break;
}

if notification.lock().unwrap().is_some() {
if raw_notification.lock().unwrap().is_some() || raw_invite.lock().unwrap().is_some() {
// We got the event.
break;
}
Expand All @@ -435,7 +438,16 @@ impl NotificationClient {
self.client.remove_event_handler(stripped_member_handler);
self.client.remove_event_handler(timeline_event_handler);

let maybe_event = notification.lock().unwrap().take();
let mut maybe_event = raw_notification.lock().unwrap().take();

if maybe_event.is_none() {
if let Some(room) = self.client.get_room(room_id) {
if room.state() == RoomState::Invited {
maybe_event = raw_invite.lock().unwrap().take();
}
}
}

Ok(maybe_event)
}

Expand Down

0 comments on commit e32ce30

Please sign in to comment.