Finish implementing Db::update_project

This commit is contained in:
Antonio Scandurra 2022-11-15 09:00:56 +01:00
parent 42bb5f0e9f
commit 3e8fcb04f7
6 changed files with 22 additions and 68 deletions

View file

@ -1515,8 +1515,23 @@ where
}
query.execute(&mut tx).await?;
let mut guest_connection_ids = Vec::new();
{
let mut db_guest_connection_ids = sqlx::query_scalar::<_, i32>(
"
SELECT connection_id
FROM project_collaborators
WHERE project_id = $1 AND is_host = FALSE
",
)
.fetch(&mut tx);
while let Some(connection_id) = db_guest_connection_ids.next().await {
guest_connection_ids.push(ConnectionId(connection_id? as u32));
}
}
let room = self.commit_room_transaction(room_id, tx).await?;
todo!()
Ok((room, guest_connection_ids))
})
.await
}

View file

@ -1100,13 +1100,10 @@ impl Server {
request.sender_connection_id,
guest_connection_ids,
|connection_id| {
self.peer.send(
self.peer.forward_send(
request.sender_connection_id,
connection_id,
proto::ProjectUpdated {
project_id: project_id.to_proto(),
worktrees: request.payload.worktrees.clone(),
room_version: room.version,
},
request.payload.clone(),
)
},
);

View file

@ -253,55 +253,6 @@ impl Store {
}
}
pub fn update_project(
&mut self,
project_id: ProjectId,
worktrees: &[proto::WorktreeMetadata],
connection_id: ConnectionId,
) -> Result<&proto::Room> {
let project = self
.projects
.get_mut(&project_id)
.ok_or_else(|| anyhow!("no such project"))?;
if project.host_connection_id == connection_id {
let mut old_worktrees = mem::take(&mut project.worktrees);
for worktree in worktrees {
if let Some(old_worktree) = old_worktrees.remove(&worktree.id) {
project.worktrees.insert(worktree.id, old_worktree);
} else {
project.worktrees.insert(
worktree.id,
Worktree {
root_name: worktree.root_name.clone(),
visible: worktree.visible,
..Default::default()
},
);
}
}
let room = self
.rooms
.get_mut(&project.room_id)
.ok_or_else(|| anyhow!("no such room"))?;
let participant_project = room
.participants
.iter_mut()
.flat_map(|participant| &mut participant.projects)
.find(|project| project.id == project_id.to_proto())
.ok_or_else(|| anyhow!("no such project"))?;
participant_project.worktree_root_names = worktrees
.iter()
.filter(|worktree| worktree.visible)
.map(|worktree| worktree.root_name.clone())
.collect();
Ok(room)
} else {
Err(anyhow!("no such project"))?
}
}
pub fn update_diagnostic_summary(
&mut self,
project_id: ProjectId,