From 3bdc8c222c4348af915498ce7faccdcf2c01d878 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Mon, 6 May 2024 18:12:56 +0800 Subject: [PATCH] chore: drop old user awarenss when open workspace (#5271) --- .../flowy-user/src/user_manager/manager_user_awareness.rs | 8 +++++++- .../flowy-user/src/user_manager/manager_user_workspace.rs | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_awareness.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_awareness.rs index e0c4b048da..826d665b39 100644 --- a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_awareness.rs +++ b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_awareness.rs @@ -7,7 +7,7 @@ use collab_entity::reminder::Reminder; use collab_entity::CollabType; use collab_integrate::collab_builder::{AppFlowyCollabBuilder, CollabBuilderConfig}; use collab_user::core::{MutexUserAwareness, UserAwareness}; -use tracing::{error, info, instrument, trace}; +use tracing::{debug, error, info, instrument, trace}; use collab_integrate::CollabKVDB; use flowy_error::{ErrorCode, FlowyError, FlowyResult}; @@ -127,6 +127,12 @@ impl UserManager { } self.is_loading_awareness.store(true, Ordering::SeqCst); + if let Some(old_user_awareness) = self.user_awareness.lock().await.take() { + debug!("Closing old user awareness"); + old_user_awareness.lock().close(); + drop(old_user_awareness); + } + let object_id = user_awareness_object_id(&session.user_uuid, &session.user_workspace.id).to_string(); trace!("Initializing user awareness {}", object_id); diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs index b14db8d75b..a6021c2ce3 100644 --- a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs +++ b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs @@ -166,6 +166,13 @@ impl UserManager { .authenticate_user .set_user_workspace(user_workspace.clone())?; + if let Err(err) = self.try_initial_user_awareness(&self.get_session()?).await { + error!( + "Failed to initialize user awareness when opening workspace: {:?}", + err + ); + } + let uid = self.user_id()?; if let Err(err) = self .user_status_callback