Start work on rejoining channel buffers

This commit is contained in:
Max Brunsfeld 2023-09-01 15:31:52 -07:00
parent 2bf417fa45
commit d370c72fbf
9 changed files with 526 additions and 163 deletions

View file

@ -17,6 +17,7 @@ pub struct ChannelBuffer {
connected: bool,
collaborators: Vec<proto::Collaborator>,
buffer: ModelHandle<language::Buffer>,
buffer_epoch: u64,
client: Arc<Client>,
subscription: Option<client::Subscription>,
}
@ -73,6 +74,7 @@ impl ChannelBuffer {
Self {
buffer,
buffer_epoch: response.epoch,
client,
connected: true,
collaborators,
@ -82,6 +84,26 @@ impl ChannelBuffer {
}))
}
pub(crate) fn replace_collaborators(
&mut self,
collaborators: Vec<proto::Collaborator>,
cx: &mut ModelContext<Self>,
) {
for old_collaborator in &self.collaborators {
if collaborators
.iter()
.any(|c| c.replica_id == old_collaborator.replica_id)
{
self.buffer.update(cx, |buffer, cx| {
buffer.remove_peer(old_collaborator.replica_id as u16, cx)
});
}
}
self.collaborators = collaborators;
cx.emit(Event::CollaboratorsChanged);
cx.notify();
}
async fn handle_update_channel_buffer(
this: ModelHandle<Self>,
update_channel_buffer: TypedEnvelope<proto::UpdateChannelBuffer>,
@ -166,6 +188,10 @@ impl ChannelBuffer {
}
}
pub fn epoch(&self) -> u64 {
self.buffer_epoch
}
pub fn buffer(&self) -> ModelHandle<language::Buffer> {
self.buffer.clone()
}
@ -179,6 +205,7 @@ impl ChannelBuffer {
}
pub(crate) fn disconnect(&mut self, cx: &mut ModelContext<Self>) {
log::info!("channel buffer {} disconnected", self.channel.id);
if self.connected {
self.connected = false;
self.subscription.take();