This commit is contained in:
Mikayla 2023-09-15 11:19:40 -07:00
parent 16707d16f6
commit f9fff3a7b2
No known key found for this signature in database
8 changed files with 166 additions and 148 deletions

View File

@ -747,7 +747,9 @@ impl ChannelStore {
}
}
let channels_changed = !payload.channels.is_empty() || !payload.delete_channels.is_empty() || !payload.delete_edge.is_empty();
let channels_changed = !payload.channels.is_empty()
|| !payload.delete_channels.is_empty()
|| !payload.delete_edge.is_empty();
if channels_changed {
if !payload.delete_channels.is_empty() {
self.channel_index.delete_channels(&payload.delete_channels);
@ -775,13 +777,10 @@ impl ChannelStore {
}
for edge in payload.delete_edge {
index_edit
.delete_edge(edge.parent_id, edge.channel_id);
index_edit.delete_edge(edge.parent_id, edge.channel_id);
}
}
for permission in payload.channel_permissions {
if permission.is_admin {
self.channels_with_admin_privileges

View File

@ -414,8 +414,9 @@ impl Database {
.filter_map(|membership| membership.admin.then_some(membership.channel_id))
.collect();
let channels = self.get_channels_internal(parents_by_child_id, true, &tx).await?;
let channels = self
.get_channels_internal(parents_by_child_id, true, &tx)
.await?;
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
enum QueryUserIdsAndChannelIds {
@ -877,7 +878,9 @@ impl Database {
channel.insert(to);
}
let channels = self.get_channels_internal(from_descendants, false, &*tx).await?;
let channels = self
.get_channels_internal(from_descendants, false, &*tx)
.await?;
Ok(channels)
}

View File

@ -535,14 +535,17 @@ async fn test_channels_moving(db: &Arc<Database>) {
// zed -- crdb - livestreaming - livestreaming_dag
// \---------/
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
],
);
// ========================================================================
// Create a new channel below a channel with multiple parents
@ -561,15 +564,18 @@ async fn test_channels_moving(db: &Arc<Database>) {
// zed -- crdb - livestreaming - livestreaming_dag - livestreaming_dag_sub_id
// \---------/
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// ========================================================================
// Test a complex DAG by making another link
@ -595,16 +601,19 @@ async fn test_channels_moving(db: &Arc<Database>) {
);
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// ========================================================================
// Test a complex DAG by making another link
@ -646,26 +655,24 @@ async fn test_channels_moving(db: &Arc<Database>) {
);
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(gpui2_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(gpui2_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// ========================================================================
// Test unlinking in a complex DAG by removing the inner link
db
.unlink_channel(
a_id,
livestreaming_dag_sub_id,
livestreaming_id,
)
db.unlink_channel(a_id, livestreaming_dag_sub_id, livestreaming_id)
.await
.unwrap();
@ -675,16 +682,19 @@ async fn test_channels_moving(db: &Arc<Database>) {
// \---------/
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(gpui2_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(gpui2_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// ========================================================================
// Test unlinking in a complex DAG by removing the inner link
@ -697,15 +707,18 @@ async fn test_channels_moving(db: &Arc<Database>) {
// zed - crdb -- livestreaming - livestreaming_dag - livestreaming_dag_sub
// \---------/
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// ========================================================================
// Test moving DAG nodes by moving livestreaming to be below gpui2
@ -718,15 +731,18 @@ async fn test_channels_moving(db: &Arc<Database>) {
// zed - crdb /
// \---------/
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(gpui2_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(gpui2_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(gpui2_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// ========================================================================
// Deleting a channel should not delete children that still have other parents
@ -736,19 +752,20 @@ async fn test_channels_moving(db: &Arc<Database>) {
// zed - crdb
// \- livestreaming - livestreaming_dag - livestreaming_dag_sub
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// ========================================================================
// Unlinking a channel from it's parent should automatically promote it to a root channel
db.unlink_channel(a_id, crdb_id, zed_id)
.await
.unwrap();
db.unlink_channel(a_id, crdb_id, zed_id).await.unwrap();
// DAG is now:
// crdb
@ -756,33 +773,36 @@ async fn test_channels_moving(db: &Arc<Database>) {
// \- livestreaming - livestreaming_dag - livestreaming_dag_sub
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, None),
(livestreaming_id, Some(zed_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, None),
(livestreaming_id, Some(zed_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// ========================================================================
// You should be able to move a root channel into a non-root channel
db.link_channel(a_id, crdb_id, zed_id)
.await
.unwrap();
db.link_channel(a_id, crdb_id, zed_id).await.unwrap();
// DAG is now:
// zed - crdb
// \- livestreaming - livestreaming_dag - livestreaming_dag_sub
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// ========================================================================
// Prep for DAG deletion test
@ -795,22 +815,23 @@ async fn test_channels_moving(db: &Arc<Database>) {
// \--------/
let result = db.get_channels_for_user(a_id).await.unwrap();
assert_dag(result.channels, &[
(zed_id, None),
(crdb_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
]);
assert_dag(
result.channels,
&[
(zed_id, None),
(crdb_id, Some(zed_id)),
(livestreaming_id, Some(zed_id)),
(livestreaming_id, Some(crdb_id)),
(livestreaming_dag_id, Some(livestreaming_id)),
(livestreaming_dag_sub_id, Some(livestreaming_dag_id)),
],
);
// Deleting the parent of a DAG should delete the whole DAG:
db.delete_channel(zed_id, a_id).await.unwrap();
let result = db.get_channels_for_user(a_id).await.unwrap();
assert!(
result.channels.is_empty()
)
assert!(result.channels.is_empty())
}
#[track_caller]

View File

@ -794,11 +794,11 @@ async fn test_joining_channels(db: &Arc<Database>) {
github_login: "user2".into(),
github_user_id: 6,
invite_count: 0,
},
)
.await
.unwrap() .user_id;
.unwrap()
.user_id;
let channel_1 = db
.create_root_channel("channel_1", "1", user_1)

View File

@ -342,7 +342,12 @@ async fn test_channel_buffer_disconnect(
let client_b = server.create_client(cx_b, "user_b").await;
let channel_id = server
.make_channel("the-channel", None, (&client_a, cx_a), &mut [(&client_b, cx_b)])
.make_channel(
"the-channel",
None,
(&client_a, cx_a),
&mut [(&client_b, cx_b)],
)
.await;
let channel_buffer_a = client_a
@ -412,7 +417,12 @@ async fn test_rejoin_channel_buffer(
let client_b = server.create_client(cx_b, "user_b").await;
let channel_id = server
.make_channel("the-channel", None, (&client_a, cx_a), &mut [(&client_b, cx_b)])
.make_channel(
"the-channel",
None,
(&client_a, cx_a),
&mut [(&client_b, cx_b)],
)
.await;
let channel_buffer_a = client_a

View File

@ -1021,13 +1021,7 @@ async fn test_channel_moving(
// Current shape for C:
// - ep
assert_channels_list_shape(
client_c.channel_store(),
cx_c,
&[
(channel_ep_id, 0),
],
);
assert_channels_list_shape(client_c.channel_store(), cx_c, &[(channel_ep_id, 0)]);
client_b
.channel_store()

View File

@ -592,16 +592,10 @@ impl TestClient {
) {
let (other_client, other_cx) = user;
self
.app_state
self.app_state
.channel_store
.update(cx_self, |channel_store, cx| {
channel_store.invite_member(
channel,
other_client.user_id().unwrap(),
true,
cx,
)
channel_store.invite_member(channel, other_client.user_id().unwrap(), true, cx)
})
.await
.unwrap();
@ -616,7 +610,6 @@ impl TestClient {
})
.await
.unwrap();
}
}

View File

@ -2129,15 +2129,13 @@ impl CollabPanel {
));
}
items.extend([
ContextMenuItem::action(
"Move this channel",
StartMoveChannel {
channel_id: location.channel,
parent_id,
},
),
]);
items.extend([ContextMenuItem::action(
"Move this channel",
StartMoveChannel {
channel_id: location.channel,
parent_id,
},
)]);
items.extend([
ContextMenuItem::Separator,