Fix notifications for membership changes too
This commit is contained in:
parent
0eff7c6ca9
commit
aa4b8d7246
12 changed files with 470 additions and 260 deletions
|
@ -410,7 +410,7 @@ async fn test_channel_buffer_disconnect(
|
|||
server.disconnect_client(client_a.peer_id().unwrap());
|
||||
deterministic.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
|
||||
|
||||
channel_buffer_a.update(cx_a, |buffer, _| {
|
||||
channel_buffer_a.update(cx_a, |buffer, cx| {
|
||||
assert_eq!(
|
||||
buffer.channel(cx).unwrap().as_ref(),
|
||||
&channel(channel_id, "the-channel", proto::ChannelRole::Admin)
|
||||
|
@ -435,7 +435,7 @@ async fn test_channel_buffer_disconnect(
|
|||
deterministic.run_until_parked();
|
||||
|
||||
// Channel buffer observed the deletion
|
||||
channel_buffer_b.update(cx_b, |buffer, _| {
|
||||
channel_buffer_b.update(cx_b, |buffer, cx| {
|
||||
assert_eq!(
|
||||
buffer.channel(cx).unwrap().as_ref(),
|
||||
&channel(channel_id, "the-channel", proto::ChannelRole::Member)
|
||||
|
@ -699,7 +699,7 @@ async fn test_following_to_channel_notes_without_a_shared_project(
|
|||
.await
|
||||
.unwrap();
|
||||
channel_view_1_a.update(cx_a, |notes, cx| {
|
||||
assert_eq!(notes.channel(cx).name, "channel-1");
|
||||
assert_eq!(notes.channel(cx).unwrap().name, "channel-1");
|
||||
notes.editor.update(cx, |editor, cx| {
|
||||
editor.insert("Hello from A.", cx);
|
||||
editor.change_selections(None, cx, |selections| {
|
||||
|
@ -731,7 +731,7 @@ async fn test_following_to_channel_notes_without_a_shared_project(
|
|||
.expect("active item is not a channel view")
|
||||
});
|
||||
channel_view_1_b.read_with(cx_b, |notes, cx| {
|
||||
assert_eq!(notes.channel(cx).name, "channel-1");
|
||||
assert_eq!(notes.channel(cx).unwrap().name, "channel-1");
|
||||
let editor = notes.editor.read(cx);
|
||||
assert_eq!(editor.text(cx), "Hello from A.");
|
||||
assert_eq!(editor.selections.ranges::<usize>(cx), &[3..4]);
|
||||
|
@ -743,7 +743,7 @@ async fn test_following_to_channel_notes_without_a_shared_project(
|
|||
.await
|
||||
.unwrap();
|
||||
channel_view_2_a.read_with(cx_a, |notes, cx| {
|
||||
assert_eq!(notes.channel(cx).name, "channel-2");
|
||||
assert_eq!(notes.channel(cx).unwrap().name, "channel-2");
|
||||
});
|
||||
|
||||
// Client B is taken to the notes for channel 2.
|
||||
|
@ -760,7 +760,7 @@ async fn test_following_to_channel_notes_without_a_shared_project(
|
|||
.expect("active item is not a channel view")
|
||||
});
|
||||
channel_view_2_b.read_with(cx_b, |notes, cx| {
|
||||
assert_eq!(notes.channel(cx).name, "channel-2");
|
||||
assert_eq!(notes.channel(cx).unwrap().name, "channel-2");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -48,13 +48,13 @@ async fn test_core_channels(
|
|||
id: channel_a_id,
|
||||
name: "channel-a".to_string(),
|
||||
depth: 0,
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
},
|
||||
ExpectedChannel {
|
||||
id: channel_b_id,
|
||||
name: "channel-b".to_string(),
|
||||
depth: 1,
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
},
|
||||
],
|
||||
);
|
||||
|
@ -95,7 +95,7 @@ async fn test_core_channels(
|
|||
id: channel_a_id,
|
||||
name: "channel-a".to_string(),
|
||||
depth: 0,
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
}],
|
||||
);
|
||||
|
||||
|
@ -142,13 +142,13 @@ async fn test_core_channels(
|
|||
ExpectedChannel {
|
||||
id: channel_a_id,
|
||||
name: "channel-a".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
depth: 0,
|
||||
},
|
||||
ExpectedChannel {
|
||||
id: channel_b_id,
|
||||
name: "channel-b".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
depth: 1,
|
||||
},
|
||||
],
|
||||
|
@ -171,19 +171,19 @@ async fn test_core_channels(
|
|||
ExpectedChannel {
|
||||
id: channel_a_id,
|
||||
name: "channel-a".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
depth: 0,
|
||||
},
|
||||
ExpectedChannel {
|
||||
id: channel_b_id,
|
||||
name: "channel-b".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
depth: 1,
|
||||
},
|
||||
ExpectedChannel {
|
||||
id: channel_c_id,
|
||||
name: "channel-c".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
depth: 2,
|
||||
},
|
||||
],
|
||||
|
@ -215,19 +215,19 @@ async fn test_core_channels(
|
|||
id: channel_a_id,
|
||||
name: "channel-a".to_string(),
|
||||
depth: 0,
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
},
|
||||
ExpectedChannel {
|
||||
id: channel_b_id,
|
||||
name: "channel-b".to_string(),
|
||||
depth: 1,
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
},
|
||||
ExpectedChannel {
|
||||
id: channel_c_id,
|
||||
name: "channel-c".to_string(),
|
||||
depth: 2,
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
},
|
||||
],
|
||||
);
|
||||
|
@ -249,7 +249,7 @@ async fn test_core_channels(
|
|||
id: channel_a_id,
|
||||
name: "channel-a".to_string(),
|
||||
depth: 0,
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
}],
|
||||
);
|
||||
assert_channels(
|
||||
|
@ -259,7 +259,7 @@ async fn test_core_channels(
|
|||
id: channel_a_id,
|
||||
name: "channel-a".to_string(),
|
||||
depth: 0,
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
}],
|
||||
);
|
||||
|
||||
|
@ -282,7 +282,7 @@ async fn test_core_channels(
|
|||
id: channel_a_id,
|
||||
name: "channel-a".to_string(),
|
||||
depth: 0,
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
}],
|
||||
);
|
||||
|
||||
|
@ -304,7 +304,7 @@ async fn test_core_channels(
|
|||
id: channel_a_id,
|
||||
name: "channel-a".to_string(),
|
||||
depth: 0,
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ async fn test_channel_room(
|
|||
id: zed_id,
|
||||
name: "zed".to_string(),
|
||||
depth: 0,
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
}],
|
||||
);
|
||||
client_b.channel_store().read_with(cx_b, |channels, _| {
|
||||
|
@ -645,7 +645,7 @@ async fn test_permissions_update_while_invited(
|
|||
depth: 0,
|
||||
id: rust_id,
|
||||
name: "rust".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
}],
|
||||
);
|
||||
assert_channels(client_b.channel_store(), cx_b, &[]);
|
||||
|
@ -673,7 +673,7 @@ async fn test_permissions_update_while_invited(
|
|||
depth: 0,
|
||||
id: rust_id,
|
||||
name: "rust".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
}],
|
||||
);
|
||||
assert_channels(client_b.channel_store(), cx_b, &[]);
|
||||
|
@ -713,7 +713,7 @@ async fn test_channel_rename(
|
|||
depth: 0,
|
||||
id: rust_id,
|
||||
name: "rust-archive".to_string(),
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
}],
|
||||
);
|
||||
|
||||
|
@ -725,7 +725,7 @@ async fn test_channel_rename(
|
|||
depth: 0,
|
||||
id: rust_id,
|
||||
name: "rust-archive".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
@ -848,7 +848,7 @@ async fn test_lost_channel_creation(
|
|||
depth: 0,
|
||||
id: channel_id,
|
||||
name: "x".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
}],
|
||||
);
|
||||
|
||||
|
@ -872,13 +872,13 @@ async fn test_lost_channel_creation(
|
|||
depth: 0,
|
||||
id: channel_id,
|
||||
name: "x".to_string(),
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
},
|
||||
ExpectedChannel {
|
||||
depth: 1,
|
||||
id: subchannel_id,
|
||||
name: "subchannel".to_string(),
|
||||
user_is_admin: true,
|
||||
role: ChannelRole::Admin,
|
||||
},
|
||||
],
|
||||
);
|
||||
|
@ -903,13 +903,13 @@ async fn test_lost_channel_creation(
|
|||
depth: 0,
|
||||
id: channel_id,
|
||||
name: "x".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
},
|
||||
ExpectedChannel {
|
||||
depth: 1,
|
||||
id: subchannel_id,
|
||||
name: "subchannel".to_string(),
|
||||
user_is_admin: false,
|
||||
role: ChannelRole::Member,
|
||||
},
|
||||
],
|
||||
);
|
||||
|
@ -969,8 +969,7 @@ async fn test_channel_link_notifications(
|
|||
|
||||
// we have an admin (a), member (b) and guest (c) all part of the zed channel.
|
||||
|
||||
// create a new private sub-channel
|
||||
// create a new priate channel, make it public, and move it under the previous one, and verify it shows for b and c
|
||||
// create a new private channel, make it public, and move it under the previous one, and verify it shows for b and not c
|
||||
let active_channel = client_a
|
||||
.channel_store()
|
||||
.update(cx_a, |channel_store, cx| {
|
||||
|
@ -1118,6 +1117,117 @@ async fn test_channel_link_notifications(
|
|||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_channel_membership_notifications(
|
||||
deterministic: Arc<Deterministic>,
|
||||
cx_a: &mut TestAppContext,
|
||||
cx_b: &mut TestAppContext,
|
||||
) {
|
||||
deterministic.forbid_parking();
|
||||
|
||||
deterministic.forbid_parking();
|
||||
|
||||
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_c").await;
|
||||
|
||||
let user_b = client_b.user_id().unwrap();
|
||||
|
||||
let channels = server
|
||||
.make_channel_tree(
|
||||
&[
|
||||
("zed", None),
|
||||
("active", Some("zed")),
|
||||
("vim", Some("active")),
|
||||
],
|
||||
(&client_a, cx_a),
|
||||
)
|
||||
.await;
|
||||
let zed_channel = channels[0];
|
||||
let _active_channel = channels[1];
|
||||
let vim_channel = channels[2];
|
||||
|
||||
try_join_all(client_a.channel_store().update(cx_a, |channel_store, cx| {
|
||||
[
|
||||
channel_store.set_channel_visibility(zed_channel, proto::ChannelVisibility::Public, cx),
|
||||
channel_store.set_channel_visibility(vim_channel, proto::ChannelVisibility::Public, cx),
|
||||
channel_store.invite_member(vim_channel, user_b, proto::ChannelRole::Member, cx),
|
||||
channel_store.invite_member(zed_channel, user_b, proto::ChannelRole::Guest, cx),
|
||||
]
|
||||
}))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
deterministic.run_until_parked();
|
||||
|
||||
client_b
|
||||
.channel_store()
|
||||
.update(cx_b, |channel_store, _| {
|
||||
channel_store.respond_to_channel_invite(zed_channel, true)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
client_b
|
||||
.channel_store()
|
||||
.update(cx_b, |channel_store, _| {
|
||||
channel_store.respond_to_channel_invite(vim_channel, true)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
deterministic.run_until_parked();
|
||||
|
||||
// we have an admin (a), and a guest (b) with access to all of zed, and membership in vim.
|
||||
assert_channels(
|
||||
client_b.channel_store(),
|
||||
cx_b,
|
||||
&[
|
||||
ExpectedChannel {
|
||||
depth: 0,
|
||||
id: zed_channel,
|
||||
name: "zed".to_string(),
|
||||
role: ChannelRole::Guest,
|
||||
},
|
||||
ExpectedChannel {
|
||||
depth: 1,
|
||||
id: vim_channel,
|
||||
name: "vim".to_string(),
|
||||
role: ChannelRole::Member,
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
client_a
|
||||
.channel_store()
|
||||
.update(cx_a, |channel_store, cx| {
|
||||
channel_store.remove_member(vim_channel, user_b, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
deterministic.run_until_parked();
|
||||
|
||||
assert_channels(
|
||||
client_b.channel_store(),
|
||||
cx_b,
|
||||
&[
|
||||
ExpectedChannel {
|
||||
depth: 0,
|
||||
id: zed_channel,
|
||||
name: "zed".to_string(),
|
||||
role: ChannelRole::Guest,
|
||||
},
|
||||
ExpectedChannel {
|
||||
depth: 1,
|
||||
id: vim_channel,
|
||||
name: "vim".to_string(),
|
||||
role: ChannelRole::Guest,
|
||||
},
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_guest_access(
|
||||
deterministic: Arc<Deterministic>,
|
||||
|
@ -1485,7 +1595,7 @@ struct ExpectedChannel {
|
|||
depth: usize,
|
||||
id: ChannelId,
|
||||
name: String,
|
||||
user_is_admin: bool,
|
||||
role: ChannelRole,
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
|
@ -1502,7 +1612,7 @@ fn assert_channel_invitations(
|
|||
depth: 0,
|
||||
name: channel.name.clone(),
|
||||
id: channel.id,
|
||||
user_is_admin: store.is_channel_admin(channel.id),
|
||||
role: channel.role,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
|
@ -1522,7 +1632,7 @@ fn assert_channels(
|
|||
depth,
|
||||
name: channel.name.clone(),
|
||||
id: channel.id,
|
||||
user_is_admin: store.is_channel_admin(channel.id),
|
||||
role: channel.role,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
|
|
|
@ -99,14 +99,14 @@ impl RandomizedTest for RandomChannelBufferTest {
|
|||
30..=40 => {
|
||||
if let Some(buffer) = channel_buffers.iter().choose(rng) {
|
||||
let channel_name =
|
||||
buffer.read_with(cx, |b, _| b.channel(cx).unwrap().name.clone());
|
||||
buffer.read_with(cx, |b, cx| b.channel(cx).unwrap().name.clone());
|
||||
break ChannelBufferOperation::LeaveChannelNotes { channel_name };
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
if let Some(buffer) = channel_buffers.iter().choose(rng) {
|
||||
break buffer.read_with(cx, |b, _| {
|
||||
break buffer.read_with(cx, |b, cx| {
|
||||
let channel_name = b.channel(cx).unwrap().name.clone();
|
||||
let edits = b
|
||||
.buffer()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue