mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: user awareness (#3185)
* refactor: separate functions * feat: init user awareness object * test: create reminder event test * docs: add documentation
This commit is contained in:
@ -110,6 +110,10 @@ impl UserService for LocalServerUserAuthServiceImpl {
|
||||
) -> FutureResult<(), Error> {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn get_user_awareness_updates(&self, _uid: i64) -> FutureResult<Vec<Vec<u8>>, Error> {
|
||||
FutureResult::new(async { Ok(vec![]) })
|
||||
}
|
||||
}
|
||||
|
||||
fn make_user_workspace() -> UserWorkspace {
|
||||
|
@ -1,4 +1,5 @@
|
||||
use anyhow::Error;
|
||||
|
||||
use flowy_error::{ErrorCode, FlowyError};
|
||||
use flowy_user_deps::cloud::UserService;
|
||||
use flowy_user_deps::entities::*;
|
||||
@ -121,6 +122,11 @@ impl UserService for SelfHostedUserAuthServiceImpl {
|
||||
// TODO(nathan): implement the RESTful API for this
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn get_user_awareness_updates(&self, _uid: i64) -> FutureResult<Vec<Vec<u8>>, Error> {
|
||||
// TODO(nathan): implement the RESTful API for this
|
||||
FutureResult::new(async { Ok(vec![]) })
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn user_sign_up_request(
|
||||
|
@ -2,6 +2,7 @@ use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Error;
|
||||
use tokio::sync::oneshot::channel;
|
||||
use uuid::Uuid;
|
||||
|
||||
use flowy_user_deps::cloud::*;
|
||||
@ -10,6 +11,7 @@ use flowy_user_deps::DEFAULT_USER_NAME;
|
||||
use lib_infra::box_any::BoxAny;
|
||||
use lib_infra::future::FutureResult;
|
||||
|
||||
use crate::supabase::api::request::FetchObjectUpdateAction;
|
||||
use crate::supabase::api::util::{ExtendedResponse, InsertParamsBuilder};
|
||||
use crate::supabase::api::{PostgresWrapper, SupabaseServerService};
|
||||
use crate::supabase::define::*;
|
||||
@ -17,17 +19,17 @@ use crate::supabase::entities::GetUserProfileParams;
|
||||
use crate::supabase::entities::UidResponse;
|
||||
use crate::supabase::entities::UserProfileResponse;
|
||||
|
||||
pub struct RESTfulSupabaseUserAuthServiceImpl<T> {
|
||||
pub struct SupabaseUserServiceImpl<T> {
|
||||
server: T,
|
||||
}
|
||||
|
||||
impl<T> RESTfulSupabaseUserAuthServiceImpl<T> {
|
||||
impl<T> SupabaseUserServiceImpl<T> {
|
||||
pub fn new(server: T) -> Self {
|
||||
Self { server }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> UserService for RESTfulSupabaseUserAuthServiceImpl<T>
|
||||
impl<T> UserService for SupabaseUserServiceImpl<T>
|
||||
where
|
||||
T: SupabaseServerService,
|
||||
{
|
||||
@ -201,6 +203,24 @@ where
|
||||
) -> FutureResult<(), Error> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_user_awareness_updates(&self, uid: i64) -> FutureResult<Vec<Vec<u8>>, Error> {
|
||||
let try_get_postgrest = self.server.try_get_weak_postgrest();
|
||||
let awareness_id = uid.to_string();
|
||||
let (tx, rx) = channel();
|
||||
tokio::spawn(async move {
|
||||
tx.send(
|
||||
async move {
|
||||
let postgrest = try_get_postgrest?;
|
||||
let action =
|
||||
FetchObjectUpdateAction::new(awareness_id, CollabType::UserAwareness, postgrest);
|
||||
action.run_with_fix_interval(5, 10).await
|
||||
}
|
||||
.await,
|
||||
)
|
||||
});
|
||||
FutureResult::new(async { rx.await? })
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_user_profile(
|
||||
|
@ -28,6 +28,7 @@ pub fn table_name(ty: &CollabType) -> String {
|
||||
CollabType::Database => format!("{}_database", AF_COLLAB_UPDATE_TABLE),
|
||||
CollabType::WorkspaceDatabase => format!("{}_w_database", AF_COLLAB_UPDATE_TABLE),
|
||||
CollabType::Folder => format!("{}_folder", AF_COLLAB_UPDATE_TABLE),
|
||||
CollabType::UserAwareness => format!("{}_user_awareness", AF_COLLAB_UPDATE_TABLE),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,9 @@ use flowy_server_config::supabase_config::SupabaseConfiguration;
|
||||
use flowy_user_deps::cloud::UserService;
|
||||
|
||||
use crate::supabase::api::{
|
||||
RESTfulPostgresServer, RESTfulSupabaseUserAuthServiceImpl, SupabaseCollabStorageImpl,
|
||||
SupabaseDatabaseServiceImpl, SupabaseDocumentServiceImpl, SupabaseFolderServiceImpl,
|
||||
SupabaseServerServiceImpl,
|
||||
RESTfulPostgresServer, SupabaseCollabStorageImpl, SupabaseDatabaseServiceImpl,
|
||||
SupabaseDocumentServiceImpl, SupabaseFolderServiceImpl, SupabaseServerServiceImpl,
|
||||
SupabaseUserServiceImpl,
|
||||
};
|
||||
use crate::supabase::entities::RealtimeCollabUpdateEvent;
|
||||
use crate::AppFlowyServer;
|
||||
@ -102,9 +102,9 @@ impl AppFlowyServer for SupabaseServer {
|
||||
}
|
||||
|
||||
fn user_service(&self) -> Arc<dyn UserService> {
|
||||
Arc::new(RESTfulSupabaseUserAuthServiceImpl::new(
|
||||
SupabaseServerServiceImpl(self.restful_postgres.clone()),
|
||||
))
|
||||
Arc::new(SupabaseUserServiceImpl::new(SupabaseServerServiceImpl(
|
||||
self.restful_postgres.clone(),
|
||||
)))
|
||||
}
|
||||
|
||||
fn folder_service(&self) -> Arc<dyn FolderCloudService> {
|
||||
|
@ -7,8 +7,8 @@ use uuid::Uuid;
|
||||
use flowy_database_deps::cloud::DatabaseCloudService;
|
||||
use flowy_folder_deps::cloud::FolderCloudService;
|
||||
use flowy_server::supabase::api::{
|
||||
RESTfulPostgresServer, RESTfulSupabaseUserAuthServiceImpl, SupabaseCollabStorageImpl,
|
||||
SupabaseDatabaseServiceImpl, SupabaseFolderServiceImpl, SupabaseServerServiceImpl,
|
||||
RESTfulPostgresServer, SupabaseCollabStorageImpl, SupabaseDatabaseServiceImpl,
|
||||
SupabaseFolderServiceImpl, SupabaseServerServiceImpl, SupabaseUserServiceImpl,
|
||||
};
|
||||
use flowy_server::supabase::define::{USER_EMAIL, USER_UUID};
|
||||
use flowy_server_config::supabase_config::SupabaseConfiguration;
|
||||
@ -42,7 +42,7 @@ pub fn database_service() -> Arc<dyn DatabaseCloudService> {
|
||||
pub fn user_auth_service() -> Arc<dyn UserService> {
|
||||
let config = SupabaseConfiguration::from_env().unwrap();
|
||||
let server = Arc::new(RESTfulPostgresServer::new(config));
|
||||
Arc::new(RESTfulSupabaseUserAuthServiceImpl::new(
|
||||
Arc::new(SupabaseUserServiceImpl::new(
|
||||
SupabaseServerServiceImpl::new(server),
|
||||
))
|
||||
}
|
||||
|
Reference in New Issue
Block a user