Implement Room::set_location

This commit is contained in:
Antonio Scandurra 2022-10-04 11:46:01 +02:00
parent 1e45198b9f
commit 456dde200c
8 changed files with 256 additions and 2 deletions

View file

@ -4,6 +4,7 @@ pub mod room;
use anyhow::{anyhow, Result};
use client::{incoming_call::IncomingCall, Client, UserStore};
use gpui::{Entity, ModelContext, ModelHandle, MutableAppContext, Task};
pub use participant::ParticipantLocation;
pub use room::Room;
use std::sync::Arc;

View file

@ -2,6 +2,7 @@ use anyhow::{anyhow, Result};
use client::{proto, User};
use std::sync::Arc;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ParticipantLocation {
Project { project_id: u64 },
External,

View file

@ -4,6 +4,7 @@ use client::{incoming_call::IncomingCall, proto, Client, PeerId, TypedEnvelope,
use collections::{HashMap, HashSet};
use futures::StreamExt;
use gpui::{AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task};
use project::Project;
use std::sync::Arc;
use util::ResultExt;
@ -233,6 +234,42 @@ impl Room {
Ok(())
})
}
pub fn set_location(
&mut self,
project: Option<&ModelHandle<Project>>,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
if self.status.is_offline() {
return Task::ready(Err(anyhow!("room is offline")));
}
let client = self.client.clone();
let room_id = self.id;
let location = if let Some(project) = project {
if let Some(project_id) = project.read(cx).remote_id() {
proto::participant_location::Variant::Project(
proto::participant_location::Project { id: project_id },
)
} else {
return Task::ready(Err(anyhow!("project is not shared")));
}
} else {
proto::participant_location::Variant::External(proto::participant_location::External {})
};
cx.foreground().spawn(async move {
client
.request(proto::UpdateParticipantLocation {
room_id,
location: Some(proto::ParticipantLocation {
variant: Some(location),
}),
})
.await?;
Ok(())
})
}
}
#[derive(Copy, Clone, PartialEq, Eq)]