Re-emit notifications and events from ActiveCall

This lets us only observe and subscribe to the active call without
needing to track the underlying `Room` if it changes, which implies
writing the same boilerplate over and over.
This commit is contained in:
Antonio Scandurra 2022-10-04 18:15:56 +02:00
parent 41240351d3
commit ebee2168fc
4 changed files with 35 additions and 71 deletions

View file

@ -80,7 +80,6 @@ pub enum Event {
}
pub struct ContactsPopover {
room_subscription: Option<Subscription>,
entries: Vec<ContactEntry>,
match_candidates: Vec<StringMatchCandidate>,
list_state: ListState,
@ -159,10 +158,9 @@ impl ContactsPopover {
let active_call = ActiveCall::global(cx);
let mut subscriptions = Vec::new();
subscriptions.push(cx.observe(&user_store, |this, _, cx| this.update_entries(cx)));
subscriptions.push(cx.observe(&active_call, |this, _, cx| this.active_call_changed(cx)));
subscriptions.push(cx.observe(&active_call, |_, _, cx| cx.notify()));
let mut this = Self {
room_subscription: None,
list_state,
selection: None,
collapsed_sections: Default::default(),
@ -173,19 +171,9 @@ impl ContactsPopover {
user_store,
};
this.update_entries(cx);
this.active_call_changed(cx);
this
}
fn active_call_changed(&mut self, cx: &mut ViewContext<Self>) {
if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {
self.room_subscription = Some(cx.observe(&room, |_, _, cx| cx.notify()));
} else {
self.room_subscription = None;
}
cx.notify();
}
fn clear_filter(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
let did_clear = self.filter_editor.update(cx, |editor, cx| {
if editor.buffer().read(cx).len(cx) > 0 {