Move project sharing into Room

This commit is contained in:
Antonio Scandurra 2022-10-07 10:14:17 +02:00
parent 3d467a9491
commit b479c8c8ba
5 changed files with 210 additions and 140 deletions

View file

@ -120,10 +120,8 @@ impl ActiveCall {
};
let initial_project_id = if let Some(initial_project) = initial_project {
let room_id = room.read_with(&cx, |room, _| room.id());
Some(
initial_project
.update(&mut cx, |project, cx| project.share(room_id, cx))
room.update(&mut cx, |room, cx| room.share_project(initial_project, cx))
.await?,
)
} else {
@ -206,6 +204,30 @@ impl ActiveCall {
Ok(())
}
pub fn share_project(
&mut self,
project: ModelHandle<Project>,
cx: &mut ModelContext<Self>,
) -> Task<Result<u64>> {
if let Some((room, _)) = self.room.as_ref() {
room.update(cx, |room, cx| room.share_project(project, cx))
} else {
Task::ready(Err(anyhow!("no active call")))
}
}
pub fn set_location(
&mut self,
project: Option<&ModelHandle<Project>>,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
if let Some((room, _)) = self.room.as_ref() {
room.update(cx, |room, cx| room.set_location(project, cx))
} else {
Task::ready(Err(anyhow!("no active call")))
}
}
fn set_room(&mut self, room: Option<ModelHandle<Room>>, cx: &mut ModelContext<Self>) {
if room.as_ref() != self.room.as_ref().map(|room| &room.0) {
if let Some(room) = room {

View file

@ -240,6 +240,25 @@ impl Room {
})
}
pub(crate) fn share_project(
&mut self,
project: ModelHandle<Project>,
cx: &mut ModelContext<Self>,
) -> Task<Result<u64>> {
let request = self
.client
.request(proto::ShareProject { room_id: self.id() });
cx.spawn_weak(|_, mut cx| async move {
let response = request.await?;
project
.update(&mut cx, |project, cx| {
project.shared(response.project_id, cx)
})
.await?;
Ok(response.project_id)
})
}
pub fn set_location(
&mut self,
project: Option<&ModelHandle<Project>>,