notification_panel.rs

  1use crate::{chat_panel::ChatPanel, NotificationPanelSettings};
  2use anyhow::Result;
  3use channel::ChannelStore;
  4use client::{ChannelId, Client, Notification, User, UserStore};
  5use collections::HashMap;
  6use db::kvp::KEY_VALUE_STORE;
  7use futures::StreamExt;
  8use gpui::{
  9    actions, div, img, list, px, AnyElement, App, AsyncWindowContext, Context, CursorStyle,
 10    DismissEvent, Element, Entity, EventEmitter, FocusHandle, Focusable, InteractiveElement,
 11    IntoElement, ListAlignment, ListScrollEvent, ListState, ParentElement, Render,
 12    StatefulInteractiveElement, Styled, Task, WeakEntity, Window,
 13};
 14use notifications::{NotificationEntry, NotificationEvent, NotificationStore};
 15use project::Fs;
 16use rpc::proto;
 17use serde::{Deserialize, Serialize};
 18use settings::{Settings, SettingsStore};
 19use std::{sync::Arc, time::Duration};
 20use time::{OffsetDateTime, UtcOffset};
 21use ui::{
 22    h_flex, prelude::*, v_flex, Avatar, Button, Icon, IconButton, IconName, Label, Tab, Tooltip,
 23};
 24use util::{ResultExt, TryFutureExt};
 25use workspace::notifications::NotificationId;
 26use workspace::{
 27    dock::{DockPosition, Panel, PanelEvent},
 28    Workspace,
 29};
 30
 31const LOADING_THRESHOLD: usize = 30;
 32const MARK_AS_READ_DELAY: Duration = Duration::from_secs(1);
 33const TOAST_DURATION: Duration = Duration::from_secs(5);
 34const NOTIFICATION_PANEL_KEY: &str = "NotificationPanel";
 35
 36pub struct NotificationPanel {
 37    client: Arc<Client>,
 38    user_store: Entity<UserStore>,
 39    channel_store: Entity<ChannelStore>,
 40    notification_store: Entity<NotificationStore>,
 41    fs: Arc<dyn Fs>,
 42    width: Option<Pixels>,
 43    active: bool,
 44    notification_list: ListState,
 45    pending_serialization: Task<Option<()>>,
 46    subscriptions: Vec<gpui::Subscription>,
 47    workspace: WeakEntity<Workspace>,
 48    current_notification_toast: Option<(u64, Task<()>)>,
 49    local_timezone: UtcOffset,
 50    focus_handle: FocusHandle,
 51    mark_as_read_tasks: HashMap<u64, Task<Result<()>>>,
 52    unseen_notifications: Vec<NotificationEntry>,
 53}
 54
 55#[derive(Serialize, Deserialize)]
 56struct SerializedNotificationPanel {
 57    width: Option<Pixels>,
 58}
 59
 60#[derive(Debug)]
 61pub enum Event {
 62    DockPositionChanged,
 63    Focus,
 64    Dismissed,
 65}
 66
 67pub struct NotificationPresenter {
 68    pub actor: Option<Arc<client::User>>,
 69    pub text: String,
 70    pub icon: &'static str,
 71    pub needs_response: bool,
 72    pub can_navigate: bool,
 73}
 74
 75actions!(notification_panel, [ToggleFocus]);
 76
 77pub fn init(cx: &mut App) {
 78    cx.observe_new(|workspace: &mut Workspace, _, _| {
 79        workspace.register_action(|workspace, _: &ToggleFocus, window, cx| {
 80            workspace.toggle_panel_focus::<NotificationPanel>(window, cx);
 81        });
 82    })
 83    .detach();
 84}
 85
 86impl NotificationPanel {
 87    pub fn new(
 88        workspace: &mut Workspace,
 89        window: &mut Window,
 90        cx: &mut Context<Workspace>,
 91    ) -> Entity<Self> {
 92        let fs = workspace.app_state().fs.clone();
 93        let client = workspace.app_state().client.clone();
 94        let user_store = workspace.app_state().user_store.clone();
 95        let workspace_handle = workspace.weak_handle();
 96
 97        cx.new(|cx| {
 98            let mut status = client.status();
 99            cx.spawn_in(window, |this, mut cx| async move {
100                while (status.next().await).is_some() {
101                    if this
102                        .update(&mut cx, |_: &mut Self, cx| {
103                            cx.notify();
104                        })
105                        .is_err()
106                    {
107                        break;
108                    }
109                }
110            })
111            .detach();
112
113            let entity = cx.entity().downgrade();
114            let notification_list =
115                ListState::new(0, ListAlignment::Top, px(1000.), move |ix, window, cx| {
116                    entity
117                        .upgrade()
118                        .and_then(|entity| {
119                            entity.update(cx, |this, cx| this.render_notification(ix, window, cx))
120                        })
121                        .unwrap_or_else(|| div().into_any())
122                });
123            notification_list.set_scroll_handler(cx.listener(
124                |this, event: &ListScrollEvent, _, cx| {
125                    if event.count.saturating_sub(event.visible_range.end) < LOADING_THRESHOLD {
126                        if let Some(task) = this
127                            .notification_store
128                            .update(cx, |store, cx| store.load_more_notifications(false, cx))
129                        {
130                            task.detach();
131                        }
132                    }
133                },
134            ));
135
136            let local_offset = chrono::Local::now().offset().local_minus_utc();
137            let mut this = Self {
138                fs,
139                client,
140                user_store,
141                local_timezone: UtcOffset::from_whole_seconds(local_offset).unwrap(),
142                channel_store: ChannelStore::global(cx),
143                notification_store: NotificationStore::global(cx),
144                notification_list,
145                pending_serialization: Task::ready(None),
146                workspace: workspace_handle,
147                focus_handle: cx.focus_handle(),
148                current_notification_toast: None,
149                subscriptions: Vec::new(),
150                active: false,
151                mark_as_read_tasks: HashMap::default(),
152                width: None,
153                unseen_notifications: Vec::new(),
154            };
155
156            let mut old_dock_position = this.position(window, cx);
157            this.subscriptions.extend([
158                cx.observe(&this.notification_store, |_, _, cx| cx.notify()),
159                cx.subscribe_in(
160                    &this.notification_store,
161                    window,
162                    Self::on_notification_event,
163                ),
164                cx.observe_global_in::<SettingsStore>(
165                    window,
166                    move |this: &mut Self, window, cx| {
167                        let new_dock_position = this.position(window, cx);
168                        if new_dock_position != old_dock_position {
169                            old_dock_position = new_dock_position;
170                            cx.emit(Event::DockPositionChanged);
171                        }
172                        cx.notify();
173                    },
174                ),
175            ]);
176            this
177        })
178    }
179
180    pub fn load(
181        workspace: WeakEntity<Workspace>,
182        cx: AsyncWindowContext,
183    ) -> Task<Result<Entity<Self>>> {
184        cx.spawn(|mut cx| async move {
185            let serialized_panel = if let Some(panel) = cx
186                .background_executor()
187                .spawn(async move { KEY_VALUE_STORE.read_kvp(NOTIFICATION_PANEL_KEY) })
188                .await
189                .log_err()
190                .flatten()
191            {
192                Some(serde_json::from_str::<SerializedNotificationPanel>(&panel)?)
193            } else {
194                None
195            };
196
197            workspace.update_in(&mut cx, |workspace, window, cx| {
198                let panel = Self::new(workspace, window, cx);
199                if let Some(serialized_panel) = serialized_panel {
200                    panel.update(cx, |panel, cx| {
201                        panel.width = serialized_panel.width.map(|w| w.round());
202                        cx.notify();
203                    });
204                }
205                panel
206            })
207        })
208    }
209
210    fn serialize(&mut self, cx: &mut Context<Self>) {
211        let width = self.width;
212        self.pending_serialization = cx.background_executor().spawn(
213            async move {
214                KEY_VALUE_STORE
215                    .write_kvp(
216                        NOTIFICATION_PANEL_KEY.into(),
217                        serde_json::to_string(&SerializedNotificationPanel { width })?,
218                    )
219                    .await?;
220                anyhow::Ok(())
221            }
222            .log_err(),
223        );
224    }
225
226    fn render_notification(
227        &mut self,
228        ix: usize,
229        window: &mut Window,
230        cx: &mut Context<Self>,
231    ) -> Option<AnyElement> {
232        let entry = self.notification_store.read(cx).notification_at(ix)?;
233        let notification_id = entry.id;
234        let now = OffsetDateTime::now_utc();
235        let timestamp = entry.timestamp;
236        let NotificationPresenter {
237            actor,
238            text,
239            needs_response,
240            can_navigate,
241            ..
242        } = self.present_notification(entry, cx)?;
243
244        let response = entry.response;
245        let notification = entry.notification.clone();
246
247        if self.active && !entry.is_read {
248            self.did_render_notification(notification_id, &notification, window, cx);
249        }
250
251        let relative_timestamp = time_format::format_localized_timestamp(
252            timestamp,
253            now,
254            self.local_timezone,
255            time_format::TimestampFormat::Relative,
256        );
257
258        let absolute_timestamp = time_format::format_localized_timestamp(
259            timestamp,
260            now,
261            self.local_timezone,
262            time_format::TimestampFormat::Absolute,
263        );
264
265        Some(
266            div()
267                .id(ix)
268                .flex()
269                .flex_row()
270                .size_full()
271                .px_2()
272                .py_1()
273                .gap_2()
274                .hover(|style| style.bg(cx.theme().colors().element_hover))
275                .when(can_navigate, |el| {
276                    el.cursor(CursorStyle::PointingHand).on_click({
277                        let notification = notification.clone();
278                        cx.listener(move |this, _, window, cx| {
279                            this.did_click_notification(&notification, window, cx)
280                        })
281                    })
282                })
283                .children(actor.map(|actor| {
284                    img(actor.avatar_uri.clone())
285                        .flex_none()
286                        .w_8()
287                        .h_8()
288                        .rounded_full()
289                }))
290                .child(
291                    v_flex()
292                        .gap_1()
293                        .size_full()
294                        .overflow_hidden()
295                        .child(Label::new(text.clone()))
296                        .child(
297                            h_flex()
298                                .child(
299                                    div()
300                                        .id("notification_timestamp")
301                                        .hover(|style| {
302                                            style
303                                                .bg(cx.theme().colors().element_selected)
304                                                .rounded_md()
305                                        })
306                                        .child(Label::new(relative_timestamp).color(Color::Muted))
307                                        .tooltip(move |_, cx| {
308                                            Tooltip::simple(absolute_timestamp.clone(), cx)
309                                        }),
310                                )
311                                .children(if let Some(is_accepted) = response {
312                                    Some(div().flex().flex_grow().justify_end().child(Label::new(
313                                        if is_accepted {
314                                            "You accepted"
315                                        } else {
316                                            "You declined"
317                                        },
318                                    )))
319                                } else if needs_response {
320                                    Some(
321                                        h_flex()
322                                            .flex_grow()
323                                            .justify_end()
324                                            .child(Button::new("decline", "Decline").on_click({
325                                                let notification = notification.clone();
326                                                let entity = cx.entity().clone();
327                                                move |_, _, cx| {
328                                                    entity.update(cx, |this, cx| {
329                                                        this.respond_to_notification(
330                                                            notification.clone(),
331                                                            false,
332                                                            cx,
333                                                        )
334                                                    });
335                                                }
336                                            }))
337                                            .child(Button::new("accept", "Accept").on_click({
338                                                let notification = notification.clone();
339                                                let entity = cx.entity().clone();
340                                                move |_, _, cx| {
341                                                    entity.update(cx, |this, cx| {
342                                                        this.respond_to_notification(
343                                                            notification.clone(),
344                                                            true,
345                                                            cx,
346                                                        )
347                                                    });
348                                                }
349                                            })),
350                                    )
351                                } else {
352                                    None
353                                }),
354                        ),
355                )
356                .into_any(),
357        )
358    }
359
360    fn present_notification(
361        &self,
362        entry: &NotificationEntry,
363        cx: &App,
364    ) -> Option<NotificationPresenter> {
365        let user_store = self.user_store.read(cx);
366        let channel_store = self.channel_store.read(cx);
367        match entry.notification {
368            Notification::ContactRequest { sender_id } => {
369                let requester = user_store.get_cached_user(sender_id)?;
370                Some(NotificationPresenter {
371                    icon: "icons/plus.svg",
372                    text: format!("{} wants to add you as a contact", requester.github_login),
373                    needs_response: user_store.has_incoming_contact_request(requester.id),
374                    actor: Some(requester),
375                    can_navigate: false,
376                })
377            }
378            Notification::ContactRequestAccepted { responder_id } => {
379                let responder = user_store.get_cached_user(responder_id)?;
380                Some(NotificationPresenter {
381                    icon: "icons/plus.svg",
382                    text: format!("{} accepted your contact invite", responder.github_login),
383                    needs_response: false,
384                    actor: Some(responder),
385                    can_navigate: false,
386                })
387            }
388            Notification::ChannelInvitation {
389                ref channel_name,
390                channel_id,
391                inviter_id,
392            } => {
393                let inviter = user_store.get_cached_user(inviter_id)?;
394                Some(NotificationPresenter {
395                    icon: "icons/hash.svg",
396                    text: format!(
397                        "{} invited you to join the #{channel_name} channel",
398                        inviter.github_login
399                    ),
400                    needs_response: channel_store.has_channel_invitation(ChannelId(channel_id)),
401                    actor: Some(inviter),
402                    can_navigate: false,
403                })
404            }
405            Notification::ChannelMessageMention {
406                sender_id,
407                channel_id,
408                message_id,
409            } => {
410                let sender = user_store.get_cached_user(sender_id)?;
411                let channel = channel_store.channel_for_id(ChannelId(channel_id))?;
412                let message = self
413                    .notification_store
414                    .read(cx)
415                    .channel_message_for_id(message_id)?;
416                Some(NotificationPresenter {
417                    icon: "icons/conversations.svg",
418                    text: format!(
419                        "{} mentioned you in #{}:\n{}",
420                        sender.github_login, channel.name, message.body,
421                    ),
422                    needs_response: false,
423                    actor: Some(sender),
424                    can_navigate: true,
425                })
426            }
427        }
428    }
429
430    fn did_render_notification(
431        &mut self,
432        notification_id: u64,
433        notification: &Notification,
434        window: &mut Window,
435        cx: &mut Context<Self>,
436    ) {
437        let should_mark_as_read = match notification {
438            Notification::ContactRequestAccepted { .. } => true,
439            Notification::ContactRequest { .. }
440            | Notification::ChannelInvitation { .. }
441            | Notification::ChannelMessageMention { .. } => false,
442        };
443
444        if should_mark_as_read {
445            self.mark_as_read_tasks
446                .entry(notification_id)
447                .or_insert_with(|| {
448                    let client = self.client.clone();
449                    cx.spawn_in(window, |this, mut cx| async move {
450                        cx.background_executor().timer(MARK_AS_READ_DELAY).await;
451                        client
452                            .request(proto::MarkNotificationRead { notification_id })
453                            .await?;
454                        this.update(&mut cx, |this, _| {
455                            this.mark_as_read_tasks.remove(&notification_id);
456                        })?;
457                        Ok(())
458                    })
459                });
460        }
461    }
462
463    fn did_click_notification(
464        &mut self,
465        notification: &Notification,
466        window: &mut Window,
467        cx: &mut Context<Self>,
468    ) {
469        if let Notification::ChannelMessageMention {
470            message_id,
471            channel_id,
472            ..
473        } = notification.clone()
474        {
475            if let Some(workspace) = self.workspace.upgrade() {
476                window.defer(cx, move |window, cx| {
477                    workspace.update(cx, |workspace, cx| {
478                        if let Some(panel) = workspace.focus_panel::<ChatPanel>(window, cx) {
479                            panel.update(cx, |panel, cx| {
480                                panel
481                                    .select_channel(ChannelId(channel_id), Some(message_id), cx)
482                                    .detach_and_log_err(cx);
483                            });
484                        }
485                    });
486                });
487            }
488        }
489    }
490
491    fn is_showing_notification(&self, notification: &Notification, cx: &mut Context<Self>) -> bool {
492        if !self.active {
493            return false;
494        }
495
496        if let Notification::ChannelMessageMention { channel_id, .. } = &notification {
497            if let Some(workspace) = self.workspace.upgrade() {
498                return if let Some(panel) = workspace.read(cx).panel::<ChatPanel>(cx) {
499                    let panel = panel.read(cx);
500                    panel.is_scrolled_to_bottom()
501                        && panel
502                            .active_chat()
503                            .map_or(false, |chat| chat.read(cx).channel_id.0 == *channel_id)
504                } else {
505                    false
506                };
507            }
508        }
509
510        false
511    }
512
513    fn on_notification_event(
514        &mut self,
515        _: &Entity<NotificationStore>,
516        event: &NotificationEvent,
517        window: &mut Window,
518        cx: &mut Context<Self>,
519    ) {
520        match event {
521            NotificationEvent::NewNotification { entry } => {
522                if !self.is_showing_notification(&entry.notification, cx) {
523                    self.unseen_notifications.push(entry.clone());
524                }
525                self.add_toast(entry, window, cx);
526            }
527            NotificationEvent::NotificationRemoved { entry }
528            | NotificationEvent::NotificationRead { entry } => {
529                self.unseen_notifications.retain(|n| n.id != entry.id);
530                self.remove_toast(entry.id, cx);
531            }
532            NotificationEvent::NotificationsUpdated {
533                old_range,
534                new_count,
535            } => {
536                self.notification_list.splice(old_range.clone(), *new_count);
537                cx.notify();
538            }
539        }
540    }
541
542    fn add_toast(
543        &mut self,
544        entry: &NotificationEntry,
545        window: &mut Window,
546        cx: &mut Context<Self>,
547    ) {
548        if self.is_showing_notification(&entry.notification, cx) {
549            return;
550        }
551
552        let Some(NotificationPresenter { actor, text, .. }) = self.present_notification(entry, cx)
553        else {
554            return;
555        };
556
557        let notification_id = entry.id;
558        self.current_notification_toast = Some((
559            notification_id,
560            cx.spawn_in(window, |this, mut cx| async move {
561                cx.background_executor().timer(TOAST_DURATION).await;
562                this.update(&mut cx, |this, cx| this.remove_toast(notification_id, cx))
563                    .ok();
564            }),
565        ));
566
567        self.workspace
568            .update(cx, |workspace, cx| {
569                let id = NotificationId::unique::<NotificationToast>();
570
571                workspace.dismiss_notification(&id, cx);
572                workspace.show_notification(id, cx, |cx| {
573                    let workspace = cx.entity().downgrade();
574                    cx.new(|_| NotificationToast {
575                        notification_id,
576                        actor,
577                        text,
578                        workspace,
579                    })
580                })
581            })
582            .ok();
583    }
584
585    fn remove_toast(&mut self, notification_id: u64, cx: &mut Context<Self>) {
586        if let Some((current_id, _)) = &self.current_notification_toast {
587            if *current_id == notification_id {
588                self.current_notification_toast.take();
589                self.workspace
590                    .update(cx, |workspace, cx| {
591                        let id = NotificationId::unique::<NotificationToast>();
592                        workspace.dismiss_notification(&id, cx)
593                    })
594                    .ok();
595            }
596        }
597    }
598
599    fn respond_to_notification(
600        &mut self,
601        notification: Notification,
602        response: bool,
603
604        cx: &mut Context<Self>,
605    ) {
606        self.notification_store.update(cx, |store, cx| {
607            store.respond_to_notification(notification, response, cx);
608        });
609    }
610}
611
612impl Render for NotificationPanel {
613    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
614        v_flex()
615            .size_full()
616            .child(
617                h_flex()
618                    .justify_between()
619                    .px_2()
620                    .py_1()
621                    // Match the height of the tab bar so they line up.
622                    .h(Tab::container_height(cx))
623                    .border_b_1()
624                    .border_color(cx.theme().colors().border)
625                    .child(Label::new("Notifications"))
626                    .child(Icon::new(IconName::Envelope)),
627            )
628            .map(|this| {
629                if self.client.user_id().is_none() {
630                    this.child(
631                        v_flex()
632                            .gap_2()
633                            .p_4()
634                            .child(
635                                Button::new("sign_in_prompt_button", "Sign in")
636                                    .icon_color(Color::Muted)
637                                    .icon(IconName::Github)
638                                    .icon_position(IconPosition::Start)
639                                    .style(ButtonStyle::Filled)
640                                    .full_width()
641                                    .on_click({
642                                        let client = self.client.clone();
643                                        move |_, window, cx| {
644                                            let client = client.clone();
645                                            window
646                                                .spawn(cx, move |cx| async move {
647                                                    client
648                                                        .authenticate_and_connect(true, &cx)
649                                                        .log_err()
650                                                        .await;
651                                                })
652                                                .detach()
653                                        }
654                                    }),
655                            )
656                            .child(
657                                div().flex().w_full().items_center().child(
658                                    Label::new("Sign in to view notifications.")
659                                        .color(Color::Muted)
660                                        .size(LabelSize::Small),
661                                ),
662                            ),
663                    )
664                } else if self.notification_list.item_count() == 0 {
665                    this.child(
666                        v_flex().p_4().child(
667                            div().flex().w_full().items_center().child(
668                                Label::new("You have no notifications.")
669                                    .color(Color::Muted)
670                                    .size(LabelSize::Small),
671                            ),
672                        ),
673                    )
674                } else {
675                    this.child(list(self.notification_list.clone()).size_full())
676                }
677            })
678    }
679}
680
681impl Focusable for NotificationPanel {
682    fn focus_handle(&self, _: &App) -> FocusHandle {
683        self.focus_handle.clone()
684    }
685}
686
687impl EventEmitter<Event> for NotificationPanel {}
688impl EventEmitter<PanelEvent> for NotificationPanel {}
689
690impl Panel for NotificationPanel {
691    fn persistent_name() -> &'static str {
692        "NotificationPanel"
693    }
694
695    fn position(&self, _: &Window, cx: &App) -> DockPosition {
696        NotificationPanelSettings::get_global(cx).dock
697    }
698
699    fn position_is_valid(&self, position: DockPosition) -> bool {
700        matches!(position, DockPosition::Left | DockPosition::Right)
701    }
702
703    fn set_position(&mut self, position: DockPosition, _: &mut Window, cx: &mut Context<Self>) {
704        settings::update_settings_file::<NotificationPanelSettings>(
705            self.fs.clone(),
706            cx,
707            move |settings, _| settings.dock = Some(position),
708        );
709    }
710
711    fn size(&self, _: &Window, cx: &App) -> Pixels {
712        self.width
713            .unwrap_or_else(|| NotificationPanelSettings::get_global(cx).default_width)
714    }
715
716    fn set_size(&mut self, size: Option<Pixels>, _: &mut Window, cx: &mut Context<Self>) {
717        self.width = size;
718        self.serialize(cx);
719        cx.notify();
720    }
721
722    fn set_active(&mut self, active: bool, _: &mut Window, cx: &mut Context<Self>) {
723        self.active = active;
724
725        if self.active {
726            self.unseen_notifications = Vec::new();
727            cx.notify();
728        }
729
730        if self.notification_store.read(cx).notification_count() == 0 {
731            cx.emit(Event::Dismissed);
732        }
733    }
734
735    fn icon(&self, _: &Window, cx: &App) -> Option<IconName> {
736        let show_button = NotificationPanelSettings::get_global(cx).button;
737        if !show_button {
738            return None;
739        }
740
741        if self.unseen_notifications.is_empty() {
742            return Some(IconName::Bell);
743        }
744
745        Some(IconName::BellDot)
746    }
747
748    fn icon_tooltip(&self, _window: &Window, _cx: &App) -> Option<&'static str> {
749        Some("Notification Panel")
750    }
751
752    fn icon_label(&self, _window: &Window, cx: &App) -> Option<String> {
753        let count = self.notification_store.read(cx).unread_notification_count();
754        if count == 0 {
755            None
756        } else {
757            Some(count.to_string())
758        }
759    }
760
761    fn toggle_action(&self) -> Box<dyn gpui::Action> {
762        Box::new(ToggleFocus)
763    }
764
765    fn activation_priority(&self) -> u32 {
766        8
767    }
768}
769
770pub struct NotificationToast {
771    notification_id: u64,
772    actor: Option<Arc<User>>,
773    text: String,
774    workspace: WeakEntity<Workspace>,
775}
776
777impl NotificationToast {
778    fn focus_notification_panel(&self, window: &mut Window, cx: &mut Context<Self>) {
779        let workspace = self.workspace.clone();
780        let notification_id = self.notification_id;
781        window.defer(cx, move |window, cx| {
782            workspace
783                .update(cx, |workspace, cx| {
784                    if let Some(panel) = workspace.focus_panel::<NotificationPanel>(window, cx) {
785                        panel.update(cx, |panel, cx| {
786                            let store = panel.notification_store.read(cx);
787                            if let Some(entry) = store.notification_for_id(notification_id) {
788                                panel.did_click_notification(
789                                    &entry.clone().notification,
790                                    window,
791                                    cx,
792                                );
793                            }
794                        });
795                    }
796                })
797                .ok();
798        })
799    }
800}
801
802impl Render for NotificationToast {
803    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
804        let user = self.actor.clone();
805
806        h_flex()
807            .id("notification_panel_toast")
808            .elevation_3(cx)
809            .p_2()
810            .gap_2()
811            .children(user.map(|user| Avatar::new(user.avatar_uri.clone())))
812            .child(Label::new(self.text.clone()))
813            .child(
814                IconButton::new("close", IconName::Close)
815                    .on_click(cx.listener(|_, _, _, cx| cx.emit(DismissEvent))),
816            )
817            .on_click(cx.listener(|this, _, window, cx| {
818                this.focus_notification_panel(window, cx);
819                cx.emit(DismissEvent);
820            }))
821    }
822}
823
824impl EventEmitter<DismissEvent> for NotificationToast {}