Fix set_channel_visibility for public channels

This commit is contained in:
Conrad Irwin 2023-10-24 10:41:21 +02:00
parent e6087e0ed9
commit aa6990bb6b
4 changed files with 78 additions and 36 deletions

View file

@ -1122,7 +1122,7 @@ async fn test_channel_link_notifications(
assert_channels_list_shape(
client_c.channel_store(),
cx_c,
&[(zed_channel, 0), (helix_channel, 1)],
&[(zed_channel, 0)],
);
}
@ -1250,44 +1250,79 @@ async fn test_guest_access(
let client_b = server.create_client(cx_b, "user_b").await;
let channels = server
.make_channel_tree(&[("channel-a", None)], (&client_a, cx_a))
.make_channel_tree(
&[("channel-a", None), ("channel-b", Some("channel-a"))],
(&client_a, cx_a),
)
.await;
let channel_a_id = channels[0];
let channel_a = channels[0];
let channel_b = channels[1];
let active_call_b = cx_b.read(ActiveCall::global);
// should not be allowed to join
// Non-members should not be allowed to join
assert!(active_call_b
.update(cx_b, |call, cx| call.join_channel(channel_a_id, cx))
.update(cx_b, |call, cx| call.join_channel(channel_a, cx))
.await
.is_err());
// Make channels A and B public
client_a
.channel_store()
.update(cx_a, |channel_store, cx| {
channel_store.set_channel_visibility(channel_a_id, proto::ChannelVisibility::Public, cx)
channel_store.set_channel_visibility(channel_a, proto::ChannelVisibility::Public, cx)
})
.await
.unwrap();
client_a
.channel_store()
.update(cx_a, |channel_store, cx| {
channel_store.set_channel_visibility(channel_b, proto::ChannelVisibility::Public, cx)
})
.await
.unwrap();
// Client B joins channel A as a guest
active_call_b
.update(cx_b, |call, cx| call.join_channel(channel_a_id, cx))
.update(cx_b, |call, cx| call.join_channel(channel_a, cx))
.await
.unwrap();
deterministic.run_until_parked();
assert!(client_b
.channel_store()
.update(cx_b, |channel_store, _| channel_store
.channel_for_id(channel_a_id)
.is_some()));
assert_channels_list_shape(
client_a.channel_store(),
cx_a,
&[(channel_a, 0), (channel_b, 1)],
);
assert_channels_list_shape(
client_b.channel_store(),
cx_b,
&[(channel_a, 0), (channel_b, 1)],
);
client_a.channel_store().update(cx_a, |channel_store, _| {
let participants = channel_store.channel_participants(channel_a_id);
let participants = channel_store.channel_participants(channel_a);
assert_eq!(participants.len(), 1);
assert_eq!(participants[0].id, client_b.user_id().unwrap());
})
});
client_a
.channel_store()
.update(cx_a, |channel_store, cx| {
channel_store.set_channel_visibility(channel_a, proto::ChannelVisibility::Members, cx)
})
.await
.unwrap();
assert_channels_list_shape(client_b.channel_store(), cx_b, &[]);
active_call_b
.update(cx_b, |call, cx| call.join_channel(channel_b, cx))
.await
.unwrap();
deterministic.run_until_parked();
assert_channels_list_shape(client_b.channel_store(), cx_b, &[(channel_b, 0)]);
}
#[gpui::test]