From d7369ace6a2e911464c9d2099258203823934586 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 14 Nov 2022 15:35:39 +0100 Subject: [PATCH] Skip applying room updates if they're older than the local room state --- crates/call/src/room.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index c1b0dc191d07bb4cbb6e83ab3239260ca0e0edb1..4ba8d8effc4831599bb0e358a37fe535b3220f16 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -34,6 +34,7 @@ pub enum Event { pub struct Room { id: u64, + version: u64, live_kit: Option, status: RoomStatus, local_participant: LocalParticipant, @@ -61,6 +62,7 @@ impl Entity for Room { impl Room { fn new( id: u64, + version: u64, live_kit_connection_info: Option, client: Arc, user_store: ModelHandle, @@ -133,6 +135,7 @@ impl Room { Self { id, + version, live_kit: live_kit_room, status: RoomStatus::Online, participant_user_ids: Default::default(), @@ -161,6 +164,7 @@ impl Room { let room = cx.add_model(|cx| { Self::new( room_proto.id, + room_proto.version, response.live_kit_connection_info, client, user_store, @@ -205,6 +209,7 @@ impl Room { let room = cx.add_model(|cx| { Self::new( room_id, + 0, response.live_kit_connection_info, client, user_store, @@ -287,8 +292,6 @@ impl Room { mut room: proto::Room, cx: &mut ModelContext, ) -> Result<()> { - // TODO: honor room version. - // Filter ourselves out from the room's participants. let local_participant_ix = room .participants @@ -318,6 +321,10 @@ impl Room { futures::join!(remote_participants, pending_participants); this.update(&mut cx, |this, cx| { + if this.version >= room.version { + return; + } + this.participant_user_ids.clear(); if let Some(participant) = local_participant { @@ -422,6 +429,7 @@ impl Room { let _ = this.leave(cx); } + this.version = room.version; this.check_invariants(); cx.notify(); });