chore: fix user awareness fetch (#5048)

* chore: fix user awareness fetch

* chore: update

* chore: update
This commit is contained in:
Nathan.fooo
2024-04-03 15:43:19 +08:00
committed by GitHub
parent 38fe61ff69
commit 58fb529eaa
22 changed files with 216 additions and 172 deletions

View File

@ -5,9 +5,12 @@ use anyhow::anyhow;
use client_api::entity::workspace_dto::{
CreateWorkspaceMember, CreateWorkspaceParam, PatchWorkspaceParam, WorkspaceMemberChangeset,
};
use client_api::entity::{AFRole, AFWorkspace, AuthProvider, CollabParams, CreateCollabParams};
use client_api::entity::{
AFRole, AFWorkspace, AuthProvider, CollabParams, CreateCollabParams, QueryCollab,
QueryCollabParams,
};
use client_api::{Client, ClientConfiguration};
use collab_entity::CollabObject;
use collab_entity::{CollabObject, CollabType};
use parking_lot::RwLock;
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
@ -238,8 +241,27 @@ where
})
}
fn get_user_awareness_doc_state(&self, _uid: i64) -> FutureResult<Vec<u8>, FlowyError> {
FutureResult::new(async { Ok(vec![]) })
fn get_user_awareness_doc_state(
&self,
_uid: i64,
workspace_id: &str,
object_id: &str,
) -> FutureResult<Vec<u8>, FlowyError> {
let workspace_id = workspace_id.to_string();
let object_id = object_id.to_string();
let try_get_client = self.server.try_get_client();
FutureResult::new(async {
let params = QueryCollabParams {
workspace_id,
inner: QueryCollab {
object_id,
collab_type: CollabType::UserAwareness,
},
};
let resp = try_get_client?.get_collab(params).await?;
Ok(resp.doc_state.to_vec())
})
}
fn subscribe_user_update(&self) -> Option<UserUpdateReceiver> {

View File

@ -148,8 +148,14 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
FutureResult::new(async { Ok(vec![]) })
}
fn get_user_awareness_doc_state(&self, _uid: i64) -> FutureResult<Vec<u8>, FlowyError> {
FutureResult::new(async { Ok(vec![]) })
fn get_user_awareness_doc_state(
&self,
_uid: i64,
_workspace_id: &str,
_object_id: &str,
) -> FutureResult<Vec<u8>, FlowyError> {
// must return record not found error
FutureResult::new(async { Err(FlowyError::record_not_found()) })
}
fn reset_workspace(&self, _collab_object: CollabObject) -> FutureResult<(), FlowyError> {

View File

@ -249,16 +249,21 @@ where
})
}
fn get_user_awareness_doc_state(&self, uid: i64) -> FutureResult<Vec<u8>, FlowyError> {
fn get_user_awareness_doc_state(
&self,
_uid: i64,
_workspace_id: &str,
object_id: &str,
) -> FutureResult<Vec<u8>, FlowyError> {
let try_get_postgrest = self.server.try_get_weak_postgrest();
let awareness_id = uid.to_string();
let (tx, rx) = channel();
let object_id = object_id.to_string();
af_spawn(async move {
tx.send(
async move {
let postgrest = try_get_postgrest?;
let action =
FetchObjectUpdateAction::new(awareness_id, CollabType::UserAwareness, postgrest);
FetchObjectUpdateAction::new(object_id, CollabType::UserAwareness, postgrest);
action.run_with_fix_interval(3, 3).await
}
.await,