From 0220d7ba5de3aa706f95b93b24b8815a6a74d578 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 13 Dec 2022 11:43:09 +0100 Subject: [PATCH] Include `room_id` in `CallCanceled` message This ensures we don't accidentally cancel old calls. --- crates/call/src/call.rs | 10 +++++++-- crates/collab/src/rpc.rs | 45 +++++++++++++++++++++++++++++--------- crates/rpc/proto/zed.proto | 4 +++- crates/rpc/src/rpc.rs | 2 +- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/crates/call/src/call.rs b/crates/call/src/call.rs index 803fbb906a..c63b2e0f5b 100644 --- a/crates/call/src/call.rs +++ b/crates/call/src/call.rs @@ -94,12 +94,18 @@ impl ActiveCall { async fn handle_call_canceled( this: ModelHandle, - _: TypedEnvelope, + envelope: TypedEnvelope, _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { this.update(&mut cx, |this, _| { - *this.incoming_call.0.borrow_mut() = None; + let mut incoming_call = this.incoming_call.0.borrow_mut(); + if incoming_call + .as_ref() + .map_or(false, |call| call.room_id == envelope.payload.room_id) + { + incoming_call.take(); + } }); Ok(()) } diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index 5b0023fa99..2c1733aeb3 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -271,7 +271,13 @@ impl Server { let pool = pool.lock().await; for canceled_user_id in canceled_calls_to_user_ids { for connection_id in pool.user_connection_ids(canceled_user_id) { - peer.send(connection_id, proto::CallCanceled {}).trace_err(); + peer.send( + connection_id, + proto::CallCanceled { + room_id: room_id.to_proto(), + }, + ) + .trace_err(); } } } @@ -833,15 +839,12 @@ async fn join_room( response: Response, session: Session, ) -> Result<()> { + let room_id = RoomId::from_proto(request.id); let room = { let room = session .db() .await - .join_room( - RoomId::from_proto(request.id), - session.user_id, - session.connection_id, - ) + .join_room(room_id, session.user_id, session.connection_id) .await?; room_updated(&room, &session.peer); room.clone() @@ -854,7 +857,12 @@ async fn join_room( { session .peer - .send(connection_id, proto::CallCanceled {}) + .send( + connection_id, + proto::CallCanceled { + room_id: room_id.to_proto(), + }, + ) .trace_err(); } @@ -978,7 +986,12 @@ async fn cancel_call( { session .peer - .send(connection_id, proto::CallCanceled {}) + .send( + connection_id, + proto::CallCanceled { + room_id: room_id.to_proto(), + }, + ) .trace_err(); } response.send(proto::Ack {})?; @@ -1005,7 +1018,12 @@ async fn decline_call(message: proto::DeclineCall, session: Session) -> Result<( { session .peer - .send(connection_id, proto::CallCanceled {}) + .send( + connection_id, + proto::CallCanceled { + room_id: room_id.to_proto(), + }, + ) .trace_err(); } update_user_contacts(session.user_id, &session).await?; @@ -1922,6 +1940,7 @@ async fn update_user_contacts(user_id: UserId, session: &Session) -> Result<()> async fn leave_room_for_session(session: &Session) -> Result<()> { let mut contacts_to_update = HashSet::default(); + let room_id; let canceled_calls_to_user_ids; let live_kit_room; let delete_live_kit_room; @@ -1934,6 +1953,7 @@ async fn leave_room_for_session(session: &Session) -> Result<()> { } room_updated(&left_room.room, &session.peer); + room_id = RoomId::from_proto(left_room.room.id); canceled_calls_to_user_ids = mem::take(&mut left_room.canceled_calls_to_user_ids); live_kit_room = mem::take(&mut left_room.room.live_kit_room); delete_live_kit_room = left_room.room.participants.is_empty(); @@ -1945,7 +1965,12 @@ async fn leave_room_for_session(session: &Session) -> Result<()> { for connection_id in pool.user_connection_ids(canceled_user_id) { session .peer - .send(connection_id, proto::CallCanceled {}) + .send( + connection_id, + proto::CallCanceled { + room_id: room_id.to_proto(), + }, + ) .trace_err(); } contacts_to_update.insert(canceled_user_id); diff --git a/crates/rpc/proto/zed.proto b/crates/rpc/proto/zed.proto index f7c7bfd6bc..cf58adfe0b 100644 --- a/crates/rpc/proto/zed.proto +++ b/crates/rpc/proto/zed.proto @@ -212,7 +212,9 @@ message IncomingCall { optional ParticipantProject initial_project = 4; } -message CallCanceled {} +message CallCanceled { + uint64 room_id = 1; +} message CancelCall { uint64 room_id = 1; diff --git a/crates/rpc/src/rpc.rs b/crates/rpc/src/rpc.rs index 5ca5711d9c..1d4a4496d0 100644 --- a/crates/rpc/src/rpc.rs +++ b/crates/rpc/src/rpc.rs @@ -6,4 +6,4 @@ pub use conn::Connection; pub use peer::*; mod macros; -pub const PROTOCOL_VERSION: u32 = 40; +pub const PROTOCOL_VERSION: u32 = 41;