diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index dce217d955d749c46315991f560cb188b2b97fcb..96ca4e953055b29586c3c8cb57f678eaf87bcf56 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -1311,28 +1311,6 @@ impl Database { .await } - async fn get_guest_connection_ids( - &self, - project_id: ProjectId, - tx: &DatabaseTransaction, - ) -> Result> { - todo!() - // 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 - // ", - // ) - // .bind(project_id) - // .fetch(tx); - // while let Some(connection_id) = db_guest_connection_ids.next().await { - // guest_connection_ids.push(ConnectionId(connection_id? as u32)); - // } - // Ok(guest_connection_ids) - } - fn build_incoming_call( room: &proto::Room, called_user_id: UserId, @@ -2194,6 +2172,38 @@ impl Database { .await } + async fn project_guest_connection_ids( + &self, + project_id: ProjectId, + tx: &DatabaseTransaction, + ) -> Result> { + #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] + enum QueryAs { + ConnectionId, + } + + let mut db_guest_connection_ids = project_collaborator::Entity::find() + .select_only() + .column_as( + project_collaborator::Column::ConnectionId, + QueryAs::ConnectionId, + ) + .filter( + project_collaborator::Column::ProjectId + .eq(project_id) + .and(project_collaborator::Column::IsHost.eq(false)), + ) + .into_values::() + .stream(tx) + .await?; + + let mut guest_connection_ids = Vec::new(); + while let Some(connection_id) = db_guest_connection_ids.next().await { + guest_connection_ids.push(ConnectionId(connection_id? as u32)); + } + Ok(guest_connection_ids) + } + // access tokens pub async fn create_access_token_hash(