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:
parent
baf6097b49
commit
95e08edbb8
4 changed files with 36 additions and 8 deletions
|
@ -145,10 +145,19 @@ impl ActiveCall {
|
||||||
recipient_user_id: u64,
|
recipient_user_id: u64,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
|
let room_id = if let Some(room) = self.room() {
|
||||||
|
room.read(cx).id()
|
||||||
|
} else {
|
||||||
|
return Task::ready(Err(anyhow!("no active call")));
|
||||||
|
};
|
||||||
|
|
||||||
let client = self.client.clone();
|
let client = self.client.clone();
|
||||||
cx.foreground().spawn(async move {
|
cx.foreground().spawn(async move {
|
||||||
client
|
client
|
||||||
.request(proto::CancelCall { recipient_user_id })
|
.request(proto::CancelCall {
|
||||||
|
room_id,
|
||||||
|
recipient_user_id,
|
||||||
|
})
|
||||||
.await?;
|
.await?;
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
})
|
})
|
||||||
|
@ -178,8 +187,15 @@ impl ActiveCall {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decline_incoming(&mut self) -> Result<()> {
|
pub fn decline_incoming(&mut self) -> Result<()> {
|
||||||
*self.incoming_call.0.borrow_mut() = None;
|
let call = self
|
||||||
self.client.send(proto::DeclineCall {})?;
|
.incoming_call
|
||||||
|
.0
|
||||||
|
.borrow_mut()
|
||||||
|
.take()
|
||||||
|
.ok_or_else(|| anyhow!("no incoming call"))?;
|
||||||
|
self.client.send(proto::DeclineCall {
|
||||||
|
room_id: call.room_id,
|
||||||
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -723,6 +723,7 @@ impl Server {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut store = self.store().await;
|
let mut store = self.store().await;
|
||||||
let (room, recipient_connection_ids) = store.cancel_call(
|
let (room, recipient_connection_ids) = store.cancel_call(
|
||||||
|
request.payload.room_id,
|
||||||
UserId::from_proto(request.payload.recipient_user_id),
|
UserId::from_proto(request.payload.recipient_user_id),
|
||||||
request.sender_id,
|
request.sender_id,
|
||||||
)?;
|
)?;
|
||||||
|
@ -741,7 +742,8 @@ impl Server {
|
||||||
message: TypedEnvelope<proto::DeclineCall>,
|
message: TypedEnvelope<proto::DeclineCall>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut store = self.store().await;
|
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 {
|
for recipient_id in recipient_connection_ids {
|
||||||
self.peer
|
self.peer
|
||||||
.send(recipient_id, proto::CallCanceled {})
|
.send(recipient_id, proto::CallCanceled {})
|
||||||
|
|
|
@ -587,6 +587,7 @@ impl Store {
|
||||||
|
|
||||||
pub fn cancel_call(
|
pub fn cancel_call(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
room_id: RoomId,
|
||||||
recipient_user_id: UserId,
|
recipient_user_id: UserId,
|
||||||
canceller_connection_id: ConnectionId,
|
canceller_connection_id: ConnectionId,
|
||||||
) -> Result<(&proto::Room, HashSet<ConnectionId>)> {
|
) -> Result<(&proto::Room, HashSet<ConnectionId>)> {
|
||||||
|
@ -609,7 +610,11 @@ impl Store {
|
||||||
.ok_or_else(|| anyhow!("no active call for recipient"))?;
|
.ok_or_else(|| anyhow!("no active call for recipient"))?;
|
||||||
|
|
||||||
anyhow::ensure!(
|
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"
|
"users are on different calls"
|
||||||
);
|
);
|
||||||
anyhow::ensure!(
|
anyhow::ensure!(
|
||||||
|
@ -630,8 +635,9 @@ impl Store {
|
||||||
Ok((room, recipient.connection_ids.clone()))
|
Ok((room, recipient.connection_ids.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn call_declined(
|
pub fn decline_call(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
room_id: RoomId,
|
||||||
recipient_connection_id: ConnectionId,
|
recipient_connection_id: ConnectionId,
|
||||||
) -> Result<(&proto::Room, Vec<ConnectionId>)> {
|
) -> Result<(&proto::Room, Vec<ConnectionId>)> {
|
||||||
let recipient_user_id = self.user_id_for_connection(recipient_connection_id)?;
|
let recipient_user_id = self.user_id_for_connection(recipient_connection_id)?;
|
||||||
|
@ -640,6 +646,7 @@ impl Store {
|
||||||
.get_mut(&recipient_user_id)
|
.get_mut(&recipient_user_id)
|
||||||
.ok_or_else(|| anyhow!("no such connection"))?;
|
.ok_or_else(|| anyhow!("no such connection"))?;
|
||||||
if let Some(active_call) = recipient.active_call.take() {
|
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
|
let recipient_connection_ids = self
|
||||||
.connection_ids_for_user(recipient_user_id)
|
.connection_ids_for_user(recipient_user_id)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
|
@ -193,10 +193,13 @@ message IncomingCall {
|
||||||
message CallCanceled {}
|
message CallCanceled {}
|
||||||
|
|
||||||
message CancelCall {
|
message CancelCall {
|
||||||
uint64 recipient_user_id = 1;
|
uint64 room_id = 1;
|
||||||
|
uint64 recipient_user_id = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeclineCall {}
|
message DeclineCall {
|
||||||
|
uint64 room_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message UpdateParticipantLocation {
|
message UpdateParticipantLocation {
|
||||||
uint64 room_id = 1;
|
uint64 room_id = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue