Implement live kit promotion/demotion

This commit is contained in:
Conrad Irwin 2024-01-09 16:10:12 -07:00
parent 8669b08161
commit 4da9d61a42
9 changed files with 223 additions and 42 deletions

View file

@ -133,7 +133,7 @@ impl ChannelRole {
}
}
pub fn can_share_projects(&self) -> bool {
pub fn can_publish_to_rooms(&self) -> bool {
use ChannelRole::*;
match self {
Admin | Member => true,

View file

@ -49,7 +49,7 @@ impl Database {
if !participant
.role
.unwrap_or(ChannelRole::Member)
.can_share_projects()
.can_publish_to_rooms()
{
return Err(anyhow!("guests cannot share projects"))?;
}

View file

@ -1264,18 +1264,41 @@ async fn set_room_participant_role(
response: Response<proto::SetRoomParticipantRole>,
session: Session,
) -> Result<()> {
let room = session
.db()
.await
.set_room_participant_role(
session.user_id,
RoomId::from_proto(request.room_id),
UserId::from_proto(request.user_id),
ChannelRole::from(request.role()),
)
.await?;
let (live_kit_room, can_publish) = {
let room = session
.db()
.await
.set_room_participant_role(
session.user_id,
RoomId::from_proto(request.room_id),
UserId::from_proto(request.user_id),
ChannelRole::from(request.role()),
)
.await?;
let live_kit_room = room.live_kit_room.clone();
let can_publish = ChannelRole::from(request.role()).can_publish_to_rooms();
room_updated(&room, &session.peer);
(live_kit_room, can_publish)
};
if let Some(live_kit) = session.live_kit_client.as_ref() {
live_kit
.update_participant(
live_kit_room.clone(),
request.user_id.to_string(),
live_kit_server::proto::ParticipantPermission {
can_subscribe: true,
can_publish,
can_publish_data: can_publish,
hidden: false,
recorder: false,
},
)
.await
.trace_err();
}
room_updated(&room, &session.peer);
response.send(proto::Ack {})?;
Ok(())
}

View file

@ -1,7 +1,7 @@
use crate::tests::TestServer;
use call::ActiveCall;
use editor::Editor;
use gpui::{BackgroundExecutor, TestAppContext, VisualTestContext};
use gpui::{BackgroundExecutor, TestAppContext};
use rpc::proto;
#[gpui::test]
@ -132,5 +132,28 @@ async fn test_channel_guest_promotion(cx_a: &mut TestAppContext, cx_b: &mut Test
room_b
.update(cx_b, |room, cx| room.share_microphone(cx))
.await
.unwrap()
.unwrap();
// B is demoted
active_call_a
.update(cx_a, |call, cx| {
call.room().unwrap().update(cx, |room, cx| {
room.set_participant_role(
client_b.user_id().unwrap(),
proto::ChannelRole::Guest,
cx,
)
})
})
.await
.unwrap();
cx_a.run_until_parked();
// project and buffers are no longer editable
assert!(project_b.read_with(cx_b, |project, _| project.is_read_only()));
assert!(editor_b.update(cx_b, |editor, cx| editor.read_only(cx)));
assert!(room_b
.update(cx_b, |room, cx| room.share_microphone(cx))
.await
.is_err());
}