Stop following when leader disconnects

This commit is contained in:
Antonio Scandurra 2022-03-22 11:15:39 +01:00
parent ffaf409a31
commit e5a99cf8cd
3 changed files with 60 additions and 10 deletions

View file

@ -667,8 +667,14 @@ impl Workspace {
.detach();
cx.subscribe(&params.project, move |this, project, event, cx| {
if let project::Event::RemoteIdChanged(remote_id) = event {
this.project_remote_id_changed(*remote_id, cx);
match event {
project::Event::RemoteIdChanged(remote_id) => {
this.project_remote_id_changed(*remote_id, cx);
}
project::Event::CollaboratorLeft(peer_id) => {
this.collaborator_left(*peer_id, cx);
}
_ => {}
}
if project.read(cx).is_read_only() {
cx.blur();
@ -1241,6 +1247,20 @@ impl Workspace {
}
}
fn collaborator_left(&mut self, peer_id: PeerId, cx: &mut ViewContext<Self>) {
self.leader_state.followers.remove(&peer_id);
if let Some(states_by_pane) = self.follower_states_by_leader.remove(&peer_id) {
for state in states_by_pane.into_values() {
for item in state.items_by_leader_view_id.into_values() {
if let FollowerItem::Loaded(item) = item {
item.set_leader_replica_id(None, cx);
}
}
}
}
cx.notify();
}
pub fn toggle_follow(
&mut self,
ToggleFollow(leader_id): &ToggleFollow,