Remove logic for multiple channel parents (#3162)

This PR simplifies our state management for channels, and logic for
inheriting channel permissions, by removing the ability for channels to
have multiple parent channels.
This commit is contained in:
Max Brunsfeld 2023-10-25 15:57:55 +02:00 committed by GitHub
commit 90f65ec9fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 879 additions and 2093 deletions

View file

@ -3,7 +3,7 @@ use crate::{
tests::TestServer,
};
use call::ActiveCall;
use channel::{Channel, ACKNOWLEDGE_DEBOUNCE_INTERVAL};
use channel::ACKNOWLEDGE_DEBOUNCE_INTERVAL;
use client::ParticipantIndex;
use client::{Collaborator, UserId};
use collab_ui::channel_view::ChannelView;
@ -11,10 +11,7 @@ use collections::HashMap;
use editor::{Anchor, Editor, ToOffset};
use futures::future;
use gpui::{executor::Deterministic, ModelHandle, TestAppContext, ViewContext};
use rpc::{
proto::{self, PeerId},
RECEIVE_TIMEOUT,
};
use rpc::{proto::PeerId, RECEIVE_TIMEOUT};
use serde_json::json;
use std::{ops::Range, sync::Arc};
@ -411,10 +408,7 @@ async fn test_channel_buffer_disconnect(
deterministic.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
channel_buffer_a.update(cx_a, |buffer, cx| {
assert_eq!(
buffer.channel(cx).unwrap().as_ref(),
&channel(channel_id, "the-channel", proto::ChannelRole::Admin)
);
assert_eq!(buffer.channel(cx).unwrap().name, "the-channel");
assert!(!buffer.is_connected());
});
@ -441,17 +435,6 @@ async fn test_channel_buffer_disconnect(
});
}
fn channel(id: u64, name: &'static str, role: proto::ChannelRole) -> Channel {
Channel {
id,
role,
name: name.to_string(),
visibility: proto::ChannelVisibility::Members,
unseen_note_version: None,
unseen_message_id: None,
}
}
#[gpui::test]
async fn test_rejoin_channel_buffer(
deterministic: Arc<Deterministic>,

View file

@ -61,10 +61,7 @@ async fn test_core_channels(
);
client_b.channel_store().read_with(cx_b, |channels, _| {
assert!(channels
.channel_dag_entries()
.collect::<Vec<_>>()
.is_empty())
assert!(channels.ordered_channels().collect::<Vec<_>>().is_empty())
});
// Invite client B to channel A as client A.
@ -1019,7 +1016,7 @@ async fn test_channel_link_notifications(
client_a
.channel_store()
.update(cx_a, |channel_store, cx| {
channel_store.link_channel(vim_channel, active_channel, cx)
channel_store.move_channel(vim_channel, Some(active_channel), cx)
})
.await
.unwrap();
@ -1054,7 +1051,7 @@ async fn test_channel_link_notifications(
client_a
.channel_store()
.update(cx_a, |channel_store, cx| {
channel_store.link_channel(helix_channel, vim_channel, cx)
channel_store.move_channel(helix_channel, Some(vim_channel), cx)
})
.await
.unwrap();
@ -1427,7 +1424,7 @@ async fn test_channel_moving(
client_a
.channel_store()
.update(cx_a, |channel_store, cx| {
channel_store.move_channel(channel_d_id, channel_c_id, channel_b_id, cx)
channel_store.move_channel(channel_d_id, Some(channel_b_id), cx)
})
.await
.unwrap();
@ -1445,189 +1442,6 @@ async fn test_channel_moving(
(channel_d_id, 2),
],
);
// TODO: Restore this test once we have a way to make channel symlinks
// client_a
// .channel_store()
// .update(cx_a, |channel_store, cx| {
// channel_store.link_channel(channel_d_id, channel_c_id, cx)
// })
// .await
// .unwrap();
// // Current shape for A:
// // /------\
// // a - b -- c -- d
// assert_channels_list_shape(
// client_a.channel_store(),
// cx_a,
// &[
// (channel_a_id, 0),
// (channel_b_id, 1),
// (channel_c_id, 2),
// (channel_d_id, 3),
// (channel_d_id, 2),
// ],
// );
//
// let b_channels = server
// .make_channel_tree(
// &[
// ("channel-mu", None),
// ("channel-gamma", Some("channel-mu")),
// ("channel-epsilon", Some("channel-mu")),
// ],
// (&client_b, cx_b),
// )
// .await;
// let channel_mu_id = b_channels[0];
// let channel_ga_id = b_channels[1];
// let channel_ep_id = b_channels[2];
// // Current shape for B:
// // /- ep
// // mu -- ga
// assert_channels_list_shape(
// client_b.channel_store(),
// cx_b,
// &[(channel_mu_id, 0), (channel_ep_id, 1), (channel_ga_id, 1)],
// );
// client_a
// .add_admin_to_channel((&client_b, cx_b), channel_b_id, cx_a)
// .await;
// // Current shape for B:
// // /- ep
// // mu -- ga
// // /---------\
// // b -- c -- d
// assert_channels_list_shape(
// client_b.channel_store(),
// cx_b,
// &[
// // New channels from a
// (channel_b_id, 0),
// (channel_c_id, 1),
// (channel_d_id, 2),
// (channel_d_id, 1),
// // B's old channels
// (channel_mu_id, 0),
// (channel_ep_id, 1),
// (channel_ga_id, 1),
// ],
// );
// client_b
// .add_admin_to_channel((&client_c, cx_c), channel_ep_id, cx_b)
// .await;
// // Current shape for C:
// // - ep
// assert_channels_list_shape(client_c.channel_store(), cx_c, &[(channel_ep_id, 0)]);
// client_b
// .channel_store()
// .update(cx_b, |channel_store, cx| {
// channel_store.link_channel(channel_b_id, channel_ep_id, cx)
// })
// .await
// .unwrap();
// // Current shape for B:
// // /---------\
// // /- ep -- b -- c -- d
// // mu -- ga
// assert_channels_list_shape(
// client_b.channel_store(),
// cx_b,
// &[
// (channel_mu_id, 0),
// (channel_ep_id, 1),
// (channel_b_id, 2),
// (channel_c_id, 3),
// (channel_d_id, 4),
// (channel_d_id, 3),
// (channel_ga_id, 1),
// ],
// );
// // Current shape for C:
// // /---------\
// // ep -- b -- c -- d
// assert_channels_list_shape(
// client_c.channel_store(),
// cx_c,
// &[
// (channel_ep_id, 0),
// (channel_b_id, 1),
// (channel_c_id, 2),
// (channel_d_id, 3),
// (channel_d_id, 2),
// ],
// );
// client_b
// .channel_store()
// .update(cx_b, |channel_store, cx| {
// channel_store.link_channel(channel_ga_id, channel_b_id, cx)
// })
// .await
// .unwrap();
// // Current shape for B:
// // /---------\
// // /- ep -- b -- c -- d
// // / \
// // mu ---------- ga
// assert_channels_list_shape(
// client_b.channel_store(),
// cx_b,
// &[
// (channel_mu_id, 0),
// (channel_ep_id, 1),
// (channel_b_id, 2),
// (channel_c_id, 3),
// (channel_d_id, 4),
// (channel_d_id, 3),
// (channel_ga_id, 3),
// (channel_ga_id, 1),
// ],
// );
// // Current shape for A:
// // /------\
// // a - b -- c -- d
// // \-- ga
// assert_channels_list_shape(
// client_a.channel_store(),
// cx_a,
// &[
// (channel_a_id, 0),
// (channel_b_id, 1),
// (channel_c_id, 2),
// (channel_d_id, 3),
// (channel_d_id, 2),
// (channel_ga_id, 2),
// ],
// );
// // Current shape for C:
// // /-------\
// // ep -- b -- c -- d
// // \-- ga
// assert_channels_list_shape(
// client_c.channel_store(),
// cx_c,
// &[
// (channel_ep_id, 0),
// (channel_b_id, 1),
// (channel_c_id, 2),
// (channel_d_id, 3),
// (channel_d_id, 2),
// (channel_ga_id, 2),
// ],
// );
}
#[derive(Debug, PartialEq)]
@ -1667,7 +1481,7 @@ fn assert_channels(
) {
let actual = channel_store.read_with(cx, |store, _| {
store
.channel_dag_entries()
.ordered_channels()
.map(|(depth, channel)| ExpectedChannel {
depth,
name: channel.name.clone(),
@ -1689,7 +1503,7 @@ fn assert_channels_list_shape(
let actual = channel_store.read_with(cx, |store, _| {
store
.channel_dag_entries()
.ordered_channels()
.map(|(depth, channel)| (channel.id, depth))
.collect::<Vec<_>>()
});

View file

@ -83,7 +83,7 @@ impl RandomizedTest for RandomChannelBufferTest {
match rng.gen_range(0..100_u32) {
0..=29 => {
let channel_name = client.channel_store().read_with(cx, |store, cx| {
store.channel_dag_entries().find_map(|(_, channel)| {
store.ordered_channels().find_map(|(_, channel)| {
if store.has_open_channel_buffer(channel.id, cx) {
None
} else {
@ -131,7 +131,7 @@ impl RandomizedTest for RandomChannelBufferTest {
ChannelBufferOperation::JoinChannelNotes { channel_name } => {
let buffer = client.channel_store().update(cx, |store, cx| {
let channel_id = store
.channel_dag_entries()
.ordered_channels()
.find(|(_, c)| c.name == channel_name)
.unwrap()
.1