From 78e3370c1e701a8acbec8d8a06181002afc3ef6f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 5 Oct 2022 11:19:44 +0200 Subject: [PATCH] Set room only after project has been shared to avoid flicker --- crates/call/src/call.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/call/src/call.rs b/crates/call/src/call.rs index 4a662e42e084b07804f0e326ef5cd4efc6325715..2f64115fb5c01cda6cb9e0b09a5b239270fe4d41 100644 --- a/crates/call/src/call.rs +++ b/crates/call/src/call.rs @@ -50,9 +50,7 @@ impl ActiveCall { let room = if let Some(room) = room { room } else { - let room = cx.update(|cx| Room::create(client, user_store, cx)).await?; - this.update(&mut cx, |this, cx| this.set_room(Some(room.clone()), cx)); - room + cx.update(|cx| Room::create(client, user_store, cx)).await? }; let initial_project_id = if let Some(initial_project) = initial_project { @@ -65,6 +63,8 @@ impl ActiveCall { } else { None }; + + this.update(&mut cx, |this, cx| this.set_room(Some(room.clone()), cx)); room.update(&mut cx, |room, cx| { room.call(recipient_user_id, initial_project_id, cx) }) @@ -88,16 +88,18 @@ impl ActiveCall { } fn set_room(&mut self, room: Option>, cx: &mut ModelContext) { - if let Some(room) = room { - let subscriptions = vec![ - cx.observe(&room, |_, _, cx| cx.notify()), - cx.subscribe(&room, |_, _, event, cx| cx.emit(event.clone())), - ]; - self.room = Some((room, subscriptions)); - } else { - self.room = None; + if room.as_ref() != self.room.as_ref().map(|room| &room.0) { + if let Some(room) = room { + let subscriptions = vec![ + cx.observe(&room, |_, _, cx| cx.notify()), + cx.subscribe(&room, |_, _, event, cx| cx.emit(event.clone())), + ]; + self.room = Some((room, subscriptions)); + } else { + self.room = None; + } + cx.notify(); } - cx.notify(); } pub fn room(&self) -> Option<&ModelHandle> {