Start work on rendering channel participants in collab panel
Co-authored-by: mikayla <mikayla@zed.dev>
This commit is contained in:
parent
a9de73739a
commit
fca8cdcb8e
9 changed files with 192 additions and 60 deletions
|
@ -2200,26 +2200,6 @@ impl Database {
|
|||
))
|
||||
}
|
||||
|
||||
async fn get_channel_members_for_room(
|
||||
&self,
|
||||
room_id: RoomId,
|
||||
tx: &DatabaseTransaction,
|
||||
) -> Result<Vec<UserId>> {
|
||||
let db_room = room::Model {
|
||||
id: room_id,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let channel_users =
|
||||
if let Some(channel) = db_room.find_related(channel::Entity).one(tx).await? {
|
||||
self.get_channel_members_internal(channel.id, tx).await?
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
Ok(channel_users)
|
||||
}
|
||||
|
||||
// projects
|
||||
|
||||
pub async fn project_count_excluding_admins(&self) -> Result<usize> {
|
||||
|
|
|
@ -2412,6 +2412,15 @@ fn build_initial_channels_update(
|
|||
});
|
||||
}
|
||||
|
||||
for (channel_id, participants) in channel_participants {
|
||||
update
|
||||
.channel_participants
|
||||
.push(proto::ChannelParticipants {
|
||||
channel_id: channel_id.to_proto(),
|
||||
participant_user_ids: participants.into_iter().map(|id| id.to_proto()).collect(),
|
||||
});
|
||||
}
|
||||
|
||||
for channel in channel_invites {
|
||||
update.channel_invitations.push(proto::Channel {
|
||||
id: channel.id.to_proto(),
|
||||
|
@ -2504,12 +2513,6 @@ fn channel_updated(
|
|||
None,
|
||||
channel_members
|
||||
.iter()
|
||||
.filter(|user_id| {
|
||||
!room
|
||||
.participants
|
||||
.iter()
|
||||
.any(|p| p.user_id == user_id.to_proto())
|
||||
})
|
||||
.flat_map(|user_id| pool.user_connection_ids(*user_id)),
|
||||
|peer_id| {
|
||||
peer.send(
|
||||
|
|
|
@ -103,6 +103,9 @@ impl TestServer {
|
|||
|
||||
async fn create_client(&mut self, cx: &mut TestAppContext, name: &str) -> TestClient {
|
||||
cx.update(|cx| {
|
||||
if cx.has_global::<SettingsStore>() {
|
||||
panic!("Same cx used to create two test clients")
|
||||
}
|
||||
cx.set_global(SettingsStore::test(cx));
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use call::ActiveCall;
|
||||
use client::Channel;
|
||||
use client::{Channel, User};
|
||||
use gpui::{executor::Deterministic, TestAppContext};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -26,6 +26,7 @@ async fn test_basic_channels(
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
deterministic.run_until_parked();
|
||||
client_a.channel_store().read_with(cx_a, |channels, _| {
|
||||
assert_eq!(
|
||||
channels.channels(),
|
||||
|
@ -105,6 +106,13 @@ async fn test_basic_channels(
|
|||
.read_with(cx_b, |channels, _| assert_eq!(channels.channels(), &[]));
|
||||
}
|
||||
|
||||
fn assert_participants_eq(participants: &[Arc<User>], expected_partitipants: &[u64]) {
|
||||
assert_eq!(
|
||||
participants.iter().map(|p| p.id).collect::<Vec<_>>(),
|
||||
expected_partitipants
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_channel_room(
|
||||
deterministic: Arc<Deterministic>,
|
||||
|
@ -116,7 +124,7 @@ async fn test_channel_room(
|
|||
let mut server = TestServer::start(&deterministic).await;
|
||||
let client_a = server.create_client(cx_a, "user_a").await;
|
||||
let client_b = server.create_client(cx_b, "user_b").await;
|
||||
let client_c = server.create_client(cx_b, "user_c").await;
|
||||
let client_c = server.create_client(cx_c, "user_c").await;
|
||||
|
||||
let zed_id = server
|
||||
.make_channel(
|
||||
|
@ -134,8 +142,21 @@ async fn test_channel_room(
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
// TODO Test that B and C sees A in the channel room
|
||||
// Give everyone a chance to observe user A joining
|
||||
deterministic.run_until_parked();
|
||||
|
||||
client_a.channel_store().read_with(cx_a, |channels, _| {
|
||||
assert_participants_eq(
|
||||
channels.channel_participants(zed_id),
|
||||
&[client_a.user_id().unwrap()],
|
||||
);
|
||||
});
|
||||
|
||||
client_b.channel_store().read_with(cx_b, |channels, _| {
|
||||
assert_participants_eq(
|
||||
channels.channel_participants(zed_id),
|
||||
&[client_a.user_id().unwrap()],
|
||||
);
|
||||
assert_eq!(
|
||||
channels.channels(),
|
||||
&[Arc::new(Channel {
|
||||
|
@ -147,15 +168,41 @@ async fn test_channel_room(
|
|||
)
|
||||
});
|
||||
|
||||
client_c.channel_store().read_with(cx_c, |channels, _| {
|
||||
assert_participants_eq(
|
||||
channels.channel_participants(zed_id),
|
||||
&[client_a.user_id().unwrap()],
|
||||
);
|
||||
});
|
||||
|
||||
active_call_b
|
||||
.update(cx_b, |active_call, cx| active_call.join_channel(zed_id, cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// TODO Test that C sees A and B in the channel room
|
||||
|
||||
deterministic.run_until_parked();
|
||||
|
||||
client_a.channel_store().read_with(cx_a, |channels, _| {
|
||||
assert_participants_eq(
|
||||
channels.channel_participants(zed_id),
|
||||
&[client_a.user_id().unwrap(), client_b.user_id().unwrap()],
|
||||
);
|
||||
});
|
||||
|
||||
client_b.channel_store().read_with(cx_b, |channels, _| {
|
||||
assert_participants_eq(
|
||||
channels.channel_participants(zed_id),
|
||||
&[client_a.user_id().unwrap(), client_b.user_id().unwrap()],
|
||||
);
|
||||
});
|
||||
|
||||
client_c.channel_store().read_with(cx_c, |channels, _| {
|
||||
assert_participants_eq(
|
||||
channels.channel_participants(zed_id),
|
||||
&[client_a.user_id().unwrap(), client_b.user_id().unwrap()],
|
||||
);
|
||||
});
|
||||
|
||||
let room_a = active_call_a.read_with(cx_a, |call, _| call.room().unwrap().clone());
|
||||
room_a.read_with(cx_a, |room, _| assert!(room.is_connected()));
|
||||
assert_eq!(
|
||||
|
@ -183,14 +230,47 @@ async fn test_channel_room(
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
// TODO Make sure that C sees A leave
|
||||
deterministic.run_until_parked();
|
||||
|
||||
client_a.channel_store().read_with(cx_a, |channels, _| {
|
||||
assert_participants_eq(
|
||||
channels.channel_participants(zed_id),
|
||||
&[client_b.user_id().unwrap()],
|
||||
);
|
||||
});
|
||||
|
||||
client_b.channel_store().read_with(cx_b, |channels, _| {
|
||||
assert_participants_eq(
|
||||
channels.channel_participants(zed_id),
|
||||
&[client_b.user_id().unwrap()],
|
||||
);
|
||||
});
|
||||
|
||||
client_c.channel_store().read_with(cx_c, |channels, _| {
|
||||
assert_participants_eq(
|
||||
channels.channel_participants(zed_id),
|
||||
&[client_b.user_id().unwrap()],
|
||||
);
|
||||
});
|
||||
|
||||
active_call_b
|
||||
.update(cx_b, |active_call, cx| active_call.hang_up(cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// TODO Make sure that C sees B leave
|
||||
deterministic.run_until_parked();
|
||||
|
||||
client_a.channel_store().read_with(cx_a, |channels, _| {
|
||||
assert_participants_eq(channels.channel_participants(zed_id), &[]);
|
||||
});
|
||||
|
||||
client_b.channel_store().read_with(cx_b, |channels, _| {
|
||||
assert_participants_eq(channels.channel_participants(zed_id), &[]);
|
||||
});
|
||||
|
||||
client_c.channel_store().read_with(cx_c, |channels, _| {
|
||||
assert_participants_eq(channels.channel_participants(zed_id), &[]);
|
||||
});
|
||||
|
||||
active_call_a
|
||||
.update(cx_a, |active_call, cx| active_call.join_channel(zed_id, cx))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue