Always include room id in protos

This is redundant, but it futures-proof the ability to talk about
multiple rooms at any given time and feels safer in terms of race
conditions.
This commit is contained in:
Antonio Scandurra 2022-10-06 15:20:49 +02:00
parent baf6097b49
commit 95e08edbb8
4 changed files with 36 additions and 8 deletions

View file

@ -723,6 +723,7 @@ impl Server {
) -> Result<()> {
let mut store = self.store().await;
let (room, recipient_connection_ids) = store.cancel_call(
request.payload.room_id,
UserId::from_proto(request.payload.recipient_user_id),
request.sender_id,
)?;
@ -741,7 +742,8 @@ impl Server {
message: TypedEnvelope<proto::DeclineCall>,
) -> Result<()> {
let mut store = self.store().await;
let (room, recipient_connection_ids) = store.call_declined(message.sender_id)?;
let (room, recipient_connection_ids) =
store.decline_call(message.payload.room_id, message.sender_id)?;
for recipient_id in recipient_connection_ids {
self.peer
.send(recipient_id, proto::CallCanceled {})

View file

@ -587,6 +587,7 @@ impl Store {
pub fn cancel_call(
&mut self,
room_id: RoomId,
recipient_user_id: UserId,
canceller_connection_id: ConnectionId,
) -> Result<(&proto::Room, HashSet<ConnectionId>)> {
@ -609,7 +610,11 @@ impl Store {
.ok_or_else(|| anyhow!("no active call for recipient"))?;
anyhow::ensure!(
canceller_active_call.room_id == recipient_active_call.room_id,
canceller_active_call.room_id == room_id,
"users are on different calls"
);
anyhow::ensure!(
recipient_active_call.room_id == room_id,
"users are on different calls"
);
anyhow::ensure!(
@ -630,8 +635,9 @@ impl Store {
Ok((room, recipient.connection_ids.clone()))
}
pub fn call_declined(
pub fn decline_call(
&mut self,
room_id: RoomId,
recipient_connection_id: ConnectionId,
) -> Result<(&proto::Room, Vec<ConnectionId>)> {
let recipient_user_id = self.user_id_for_connection(recipient_connection_id)?;
@ -640,6 +646,7 @@ impl Store {
.get_mut(&recipient_user_id)
.ok_or_else(|| anyhow!("no such connection"))?;
if let Some(active_call) = recipient.active_call.take() {
anyhow::ensure!(active_call.room_id == room_id, "no such room");
let recipient_connection_ids = self
.connection_ids_for_user(recipient_user_id)
.collect::<Vec<_>>();