Dismiss contact request notification if request is cancelled
This commit is contained in:
parent
3bca1c29e2
commit
fe89de8b11
5 changed files with 100 additions and 45 deletions
|
@ -604,13 +604,20 @@ impl<T: Item> WeakItemHandle for WeakViewHandle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait Notification: View {}
|
||||
pub trait Notification: View {
|
||||
fn should_dismiss_notification_on_event(&self, event: &<Self as Entity>::Event) -> bool;
|
||||
}
|
||||
|
||||
pub trait NotificationHandle {
|
||||
fn id(&self) -> usize;
|
||||
fn to_any(&self) -> AnyViewHandle;
|
||||
}
|
||||
|
||||
impl<T: Notification> NotificationHandle for ViewHandle<T> {
|
||||
fn id(&self) -> usize {
|
||||
self.id()
|
||||
}
|
||||
|
||||
fn to_any(&self) -> AnyViewHandle {
|
||||
self.into()
|
||||
}
|
||||
|
@ -996,10 +1003,27 @@ impl Workspace {
|
|||
notification: ViewHandle<V>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
cx.subscribe(¬ification, |this, handle, event, cx| {
|
||||
if handle.read(cx).should_dismiss_notification_on_event(event) {
|
||||
this.dismiss_notification(handle.id(), cx);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
self.notifications.push(Box::new(notification));
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn dismiss_notification(&mut self, id: usize, cx: &mut ViewContext<Self>) {
|
||||
self.notifications.retain(|handle| {
|
||||
if handle.id() == id {
|
||||
cx.notify();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn items<'a>(
|
||||
&'a self,
|
||||
cx: &'a AppContext,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue