From 36a4d31b5b477269dd47b7643b8b0830287e1a1d Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 2 Jun 2022 18:04:54 -0700 Subject: [PATCH] Keep unregistered projects' ids until pending contact updates are done --- crates/client/src/user.rs | 15 +++++++++++++++ crates/project/src/project.rs | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index b8a320f524..9ac4c9a0ed 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -99,6 +99,7 @@ impl Entity for UserStore { enum UpdateContacts { Update(proto::UpdateContacts), + Wait(postage::barrier::Sender), Clear(postage::barrier::Sender), } @@ -217,6 +218,10 @@ impl UserStore { cx: &mut ModelContext, ) -> Task> { match message { + UpdateContacts::Wait(barrier) => { + drop(barrier); + Task::ready(Ok(())) + } UpdateContacts::Clear(barrier) => { self.contacts.clear(); self.incoming_contact_requests.clear(); @@ -497,6 +502,16 @@ impl UserStore { } } + pub fn contact_updates_done(&mut self) -> impl Future { + let (tx, mut rx) = postage::barrier::channel(); + self.update_contacts_tx + .unbounded_send(UpdateContacts::Wait(tx)) + .unwrap(); + async move { + rx.recv().await; + } + } + pub fn get_users( &mut self, mut user_ids: Vec, diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index a000b32492..c16cb8422e 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -654,6 +654,19 @@ impl Project { }); return cx.spawn(|this, mut cx| async move { let response = request.await; + + // Unregistering the project causes the server to send out a + // contact update removing this project from the host's list + // of public projects. Wait until this contact update has been + // processed before clearing out this project's remote id, so + // that there is no moment where this project appears in the + // contact metadata and *also* has no remote id. + this.update(&mut cx, |this, cx| { + this.user_store() + .update(cx, |store, _| store.contact_updates_done()) + }) + .await; + this.update(&mut cx, |this, cx| { if let ProjectClientState::Local { remote_id_tx, .. } = &mut this.client_state