Prototype cursor sharing (the inefficient way) (#3970)

Release Notes:

- Sync guest users' cursor positions
This commit is contained in:
Conrad Irwin 2024-01-09 22:21:24 -07:00 committed by GitHub
commit 3c2ebc3d88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View file

@ -883,6 +883,7 @@ impl Database {
&self, &self,
project_id: ProjectId, project_id: ProjectId,
connection_id: ConnectionId, connection_id: ConnectionId,
requires_write: bool,
) -> Result<RoomGuard<Vec<ProjectCollaborator>>> { ) -> Result<RoomGuard<Vec<ProjectCollaborator>>> {
let room_id = self.room_id_for_project(project_id).await?; let room_id = self.room_id_for_project(project_id).await?;
self.room_transaction(room_id, |tx| async move { self.room_transaction(room_id, |tx| async move {
@ -893,9 +894,10 @@ impl Database {
.await? .await?
.ok_or_else(|| anyhow!("no such room"))?; .ok_or_else(|| anyhow!("no such room"))?;
if !current_participant if requires_write
.role && !current_participant
.map_or(false, |role| role.can_edit_projects()) .role
.map_or(false, |role| role.can_edit_projects())
{ {
Err(anyhow!("not authorized to edit projects"))?; Err(anyhow!("not authorized to edit projects"))?;
} }

View file

@ -1859,11 +1859,24 @@ async fn update_buffer(
let mut guest_connection_ids; let mut guest_connection_ids;
let mut host_connection_id = None; let mut host_connection_id = None;
let mut requires_write_permission = false;
for op in request.operations.iter() {
match op.variant {
None | Some(proto::operation::Variant::UpdateSelections(_)) => {}
Some(_) => requires_write_permission = true,
}
}
{ {
let collaborators = session let collaborators = session
.db() .db()
.await .await
.project_collaborators_for_buffer_update(project_id, session.connection_id) .project_collaborators_for_buffer_update(
project_id,
session.connection_id,
requires_write_permission,
)
.await?; .await?;
guest_connection_ids = Vec::with_capacity(collaborators.len() - 1); guest_connection_ids = Vec::with_capacity(collaborators.len() - 1);
for collaborator in collaborators.iter() { for collaborator in collaborators.iter() {