Differentiate between follow state on a per-project basis
This commit is contained in:
parent
350b7b82f7
commit
465d8cc2ff
6 changed files with 28 additions and 19 deletions
|
@ -55,7 +55,7 @@ pub struct Room {
|
||||||
leave_when_empty: bool,
|
leave_when_empty: bool,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
follows_by_leader_id: HashMap<PeerId, Vec<PeerId>>,
|
follows_by_leader_id_project_id: HashMap<(PeerId, u64), Vec<PeerId>>,
|
||||||
subscriptions: Vec<client::Subscription>,
|
subscriptions: Vec<client::Subscription>,
|
||||||
pending_room_update: Option<Task<()>>,
|
pending_room_update: Option<Task<()>>,
|
||||||
maintain_connection: Option<Task<Option<()>>>,
|
maintain_connection: Option<Task<Option<()>>>,
|
||||||
|
@ -149,7 +149,7 @@ impl Room {
|
||||||
pending_room_update: None,
|
pending_room_update: None,
|
||||||
client,
|
client,
|
||||||
user_store,
|
user_store,
|
||||||
follows_by_leader_id: Default::default(),
|
follows_by_leader_id_project_id: Default::default(),
|
||||||
maintain_connection: Some(maintain_connection),
|
maintain_connection: Some(maintain_connection),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,9 +462,9 @@ impl Room {
|
||||||
self.participant_user_ids.contains(&user_id)
|
self.participant_user_ids.contains(&user_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn followers_for(&self, leader_id: PeerId) -> &[PeerId] {
|
pub fn followers_for(&self, leader_id: PeerId, project_id: u64) -> &[PeerId] {
|
||||||
self.follows_by_leader_id
|
self.follows_by_leader_id_project_id
|
||||||
.get(&leader_id)
|
.get(&(leader_id, project_id))
|
||||||
.map_or(&[], |v| v.as_slice())
|
.map_or(&[], |v| v.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,8 +634,9 @@ impl Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.follows_by_leader_id.clear();
|
this.follows_by_leader_id_project_id.clear();
|
||||||
for follower in room.followers {
|
for follower in room.followers {
|
||||||
|
let project_id = follower.project_id;
|
||||||
let (leader, follower) = match (follower.leader_id, follower.follower_id) {
|
let (leader, follower) = match (follower.leader_id, follower.follower_id) {
|
||||||
(Some(leader), Some(follower)) => (leader, follower),
|
(Some(leader), Some(follower)) => (leader, follower),
|
||||||
|
|
||||||
|
@ -646,8 +647,8 @@ impl Room {
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = this
|
let list = this
|
||||||
.follows_by_leader_id
|
.follows_by_leader_id_project_id
|
||||||
.entry(leader)
|
.entry((leader, project_id))
|
||||||
.or_insert(Vec::new());
|
.or_insert(Vec::new());
|
||||||
if !list.contains(&follower) {
|
if !list.contains(&follower) {
|
||||||
list.push(follower);
|
list.push(follower);
|
||||||
|
|
|
@ -1996,6 +1996,7 @@ impl Database {
|
||||||
followers.push(proto::Follower {
|
followers.push(proto::Follower {
|
||||||
leader_id: Some(db_follower.leader_connection().into()),
|
leader_id: Some(db_follower.leader_connection().into()),
|
||||||
follower_id: Some(db_follower.follower_connection().into()),
|
follower_id: Some(db_follower.follower_connection().into()),
|
||||||
|
project_id: db_follower.project_id.to_proto(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5934,7 +5934,7 @@ async fn test_following(
|
||||||
active_call.read_with(*cx, |call, cx| {
|
active_call.read_with(*cx, |call, cx| {
|
||||||
let room = call.room().unwrap().read(cx);
|
let room = call.room().unwrap().read(cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
room.followers_for(peer_id_a),
|
room.followers_for(peer_id_a, project_id),
|
||||||
&[peer_id_b, peer_id_c],
|
&[peer_id_b, peer_id_c],
|
||||||
"checking followers for A as {name}"
|
"checking followers for A as {name}"
|
||||||
);
|
);
|
||||||
|
@ -5956,7 +5956,7 @@ async fn test_following(
|
||||||
active_call.read_with(*cx, |call, cx| {
|
active_call.read_with(*cx, |call, cx| {
|
||||||
let room = call.room().unwrap().read(cx);
|
let room = call.room().unwrap().read(cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
room.followers_for(peer_id_a),
|
room.followers_for(peer_id_a, project_id),
|
||||||
&[peer_id_b],
|
&[peer_id_b],
|
||||||
"checking followers for A as {name}"
|
"checking followers for A as {name}"
|
||||||
);
|
);
|
||||||
|
|
|
@ -640,16 +640,21 @@ impl CollabTitlebarItem {
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
cx: &mut RenderContext<Self>,
|
cx: &mut RenderContext<Self>,
|
||||||
) -> ElementBox {
|
) -> ElementBox {
|
||||||
|
let project_id = workspace.read(cx).project().read(cx).remote_id();
|
||||||
let room = ActiveCall::global(cx).read(cx).room();
|
let room = ActiveCall::global(cx).read(cx).room();
|
||||||
let is_being_followed = workspace.read(cx).is_being_followed(peer_id);
|
let is_being_followed = workspace.read(cx).is_being_followed(peer_id);
|
||||||
let followed_by_self = room
|
let followed_by_self = room
|
||||||
.map(|room| {
|
.and_then(|room| {
|
||||||
|
Some(
|
||||||
is_being_followed
|
is_being_followed
|
||||||
&& room
|
&& room
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.followers_for(peer_id)
|
.followers_for(peer_id, project_id?)
|
||||||
.iter()
|
.iter()
|
||||||
.any(|&follower| Some(follower) == workspace.read(cx).client().peer_id())
|
.any(|&follower| {
|
||||||
|
Some(follower) == workspace.read(cx).client().peer_id()
|
||||||
|
}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
@ -680,8 +685,9 @@ impl CollabTitlebarItem {
|
||||||
))
|
))
|
||||||
.with_children(
|
.with_children(
|
||||||
(|| {
|
(|| {
|
||||||
|
let project_id = project_id?;
|
||||||
let room = room?.read(cx);
|
let room = room?.read(cx);
|
||||||
let followers = room.followers_for(peer_id);
|
let followers = room.followers_for(peer_id, project_id);
|
||||||
|
|
||||||
Some(followers.into_iter().flat_map(|&follower| {
|
Some(followers.into_iter().flat_map(|&follower| {
|
||||||
let remote_participant =
|
let remote_participant =
|
||||||
|
|
|
@ -231,6 +231,7 @@ message ParticipantProject {
|
||||||
message Follower {
|
message Follower {
|
||||||
PeerId leader_id = 1;
|
PeerId leader_id = 1;
|
||||||
PeerId follower_id = 2;
|
PeerId follower_id = 2;
|
||||||
|
uint64 project_id = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ParticipantLocation {
|
message ParticipantLocation {
|
||||||
|
|
|
@ -6,4 +6,4 @@ pub use conn::Connection;
|
||||||
pub use peer::*;
|
pub use peer::*;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
pub const PROTOCOL_VERSION: u32 = 48;
|
pub const PROTOCOL_VERSION: u32 = 49;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue