remove flowy-user unuse files

This commit is contained in:
appflowy 2022-01-11 13:34:45 +08:00
parent 855d396122
commit e7aad4045b
26 changed files with 163 additions and 181 deletions

View File

@ -4,7 +4,7 @@ use std::convert::TryInto;
use actix_web::web::Data;
use flowy_document::core::edit::ClientDocumentEditor;
use flowy_test::{helper::ViewTest, FlowySDKTest};
use flowy_user::services::user::UserSession;
use flowy_user::services::UserSession;
use futures_util::{stream, stream::StreamExt};
use std::sync::Arc;
use bytes::Bytes;

View File

@ -8,7 +8,7 @@ use std::{collections::HashMap, sync::Arc};
use crate::{
entities::workspace::RepeatedWorkspace,
errors::{FlowyError, FlowyResult},
module::{CoreCloudService, WorkspaceDatabase, WorkspaceUser},
module::{WorkspaceCloudService, WorkspaceDatabase, WorkspaceUser},
notify::{send_dart_notification, WorkspaceNotification},
services::{AppController, TrashController, ViewController, WorkspaceController},
};
@ -19,7 +19,7 @@ lazy_static! {
pub struct CoreContext {
pub user: Arc<dyn WorkspaceUser>,
pub(crate) cloud_service: Arc<dyn CoreCloudService>,
pub(crate) cloud_service: Arc<dyn WorkspaceCloudService>,
pub(crate) database: Arc<dyn WorkspaceDatabase>,
pub workspace_controller: Arc<WorkspaceController>,
pub(crate) app_controller: Arc<AppController>,
@ -30,7 +30,7 @@ pub struct CoreContext {
impl CoreContext {
pub(crate) fn new(
user: Arc<dyn WorkspaceUser>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
database: Arc<dyn WorkspaceDatabase>,
workspace_controller: Arc<WorkspaceController>,
app_controller: Arc<AppController>,

View File

@ -48,7 +48,7 @@ pub fn init_core(
user: Arc<dyn WorkspaceUser>,
database: Arc<dyn WorkspaceDatabase>,
flowy_document: Arc<DocumentContext>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
) -> Arc<CoreContext> {
let trash_controller = Arc::new(TrashController::new(
database.clone(),
@ -133,7 +133,7 @@ pub fn create(core: Arc<CoreContext>) -> Module {
module
}
pub trait CoreCloudService: Send + Sync {
pub trait WorkspaceCloudService: Send + Sync {
fn init(&self);
// Workspace

View File

@ -4,7 +4,7 @@ use crate::{
trash::TrashType,
},
errors::*,
module::{CoreCloudService, WorkspaceDatabase, WorkspaceUser},
module::{WorkspaceCloudService, WorkspaceDatabase, WorkspaceUser},
notify::*,
services::{
app::sql::{AppTable, AppTableChangeset, AppTableSql},
@ -20,7 +20,7 @@ pub(crate) struct AppController {
user: Arc<dyn WorkspaceUser>,
database: Arc<dyn WorkspaceDatabase>,
trash_can: Arc<TrashController>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
}
impl AppController {
@ -28,7 +28,7 @@ impl AppController {
user: Arc<dyn WorkspaceUser>,
database: Arc<dyn WorkspaceDatabase>,
trash_can: Arc<TrashController>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
) -> Self {
Self {
user,

View File

@ -1,7 +1,7 @@
use crate::{
entities::trash::{RepeatedTrash, RepeatedTrashId, Trash, TrashId, TrashType},
errors::{FlowyError, FlowyResult},
module::{CoreCloudService, WorkspaceDatabase, WorkspaceUser},
module::{WorkspaceCloudService, WorkspaceDatabase, WorkspaceUser},
notify::{send_anonymous_dart_notification, WorkspaceNotification},
services::trash::sql::TrashTableSql,
};
@ -13,14 +13,14 @@ use tokio::sync::{broadcast, mpsc};
pub struct TrashController {
pub database: Arc<dyn WorkspaceDatabase>,
notify: broadcast::Sender<TrashEvent>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
user: Arc<dyn WorkspaceUser>,
}
impl TrashController {
pub fn new(
database: Arc<dyn WorkspaceDatabase>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
user: Arc<dyn WorkspaceUser>,
) -> Self {
let (tx, _) = broadcast::channel(10);

View File

@ -13,7 +13,7 @@ use crate::{
view::{CreateViewParams, RepeatedView, UpdateViewParams, View, ViewId},
},
errors::{FlowyError, FlowyResult},
module::{CoreCloudService, WorkspaceDatabase, WorkspaceUser},
module::{WorkspaceCloudService, WorkspaceDatabase, WorkspaceUser},
notify::{send_dart_notification, WorkspaceNotification},
services::{
view::sql::{ViewTable, ViewTableChangeset, ViewTableSql},
@ -30,7 +30,7 @@ const LATEST_VIEW_ID: &str = "latest_view_id";
pub(crate) struct ViewController {
user: Arc<dyn WorkspaceUser>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
database: Arc<dyn WorkspaceDatabase>,
trash_controller: Arc<TrashController>,
document_ctx: Arc<DocumentContext>,
@ -40,7 +40,7 @@ impl ViewController {
pub(crate) fn new(
user: Arc<dyn WorkspaceUser>,
database: Arc<dyn WorkspaceDatabase>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
trash_can: Arc<TrashController>,
document_ctx: Arc<DocumentContext>,
) -> Self {

View File

@ -1,6 +1,6 @@
use crate::{
errors::*,
module::{CoreCloudService, WorkspaceDatabase, WorkspaceUser},
module::{WorkspaceCloudService, WorkspaceDatabase, WorkspaceUser},
notify::*,
services::{
read_local_workspace_apps,
@ -16,7 +16,7 @@ pub struct WorkspaceController {
pub user: Arc<dyn WorkspaceUser>,
pub(crate) database: Arc<dyn WorkspaceDatabase>,
pub(crate) trash_controller: Arc<TrashController>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
}
impl WorkspaceController {
@ -24,7 +24,7 @@ impl WorkspaceController {
user: Arc<dyn WorkspaceUser>,
database: Arc<dyn WorkspaceDatabase>,
trash_can: Arc<TrashController>,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
) -> Self {
Self {
user,

View File

@ -1,5 +1,5 @@
#![allow(clippy::type_complexity)]
use crate::module::{CoreCloudService, WorkspaceUser};
use crate::module::{WorkspaceCloudService, WorkspaceUser};
use lib_infra::retry::Action;
use pin_project::pin_project;
use std::{
@ -10,12 +10,12 @@ use std::{
task::{Context, Poll},
};
pub(crate) type Builder<Fut> = Box<dyn Fn(String, Arc<dyn CoreCloudService>) -> Fut + Send + Sync>;
pub(crate) type Builder<Fut> = Box<dyn Fn(String, Arc<dyn WorkspaceCloudService>) -> Fut + Send + Sync>;
#[allow(dead_code)]
pub(crate) struct RetryAction<Fut, T, E> {
token: String,
cloud_service: Arc<dyn CoreCloudService>,
cloud_service: Arc<dyn WorkspaceCloudService>,
user: Arc<dyn WorkspaceUser>,
builder: Builder<Fut>,
phantom: PhantomData<(T, E)>,
@ -23,10 +23,14 @@ pub(crate) struct RetryAction<Fut, T, E> {
impl<Fut, T, E> RetryAction<Fut, T, E> {
#[allow(dead_code)]
pub(crate) fn new<F>(cloud_service: Arc<dyn CoreCloudService>, user: Arc<dyn WorkspaceUser>, builder: F) -> Self
pub(crate) fn new<F>(
cloud_service: Arc<dyn WorkspaceCloudService>,
user: Arc<dyn WorkspaceUser>,
builder: F,
) -> Self
where
Fut: Future<Output = Result<T, E>> + Send + Sync + 'static,
F: Fn(String, Arc<dyn CoreCloudService>) -> Fut + Send + Sync + 'static,
F: Fn(String, Arc<dyn WorkspaceCloudService>) -> Fut + Send + Sync + 'static,
{
let token = user.token().unwrap_or_else(|_| "".to_owned());
Self {

View File

@ -1,7 +1,7 @@
use backend_service::configuration::ClientServerConfiguration;
use flowy_core::{
errors::FlowyError,
module::{CoreCloudService, WorkspaceDatabase, WorkspaceUser},
module::{WorkspaceCloudService, WorkspaceDatabase, WorkspaceUser},
prelude::{
App,
AppId,
@ -23,7 +23,7 @@ use flowy_core::{
};
use flowy_database::ConnectionPool;
use flowy_net::cloud::core::{CoreHttpCloudService, CoreLocalCloudService};
use flowy_user::services::user::UserSession;
use flowy_user::services::UserSession;
use lib_infra::future::FutureResult;
use std::sync::Arc;
@ -35,7 +35,7 @@ impl CoreDepsResolver {
) -> (
Arc<dyn WorkspaceUser>,
Arc<dyn WorkspaceDatabase>,
Arc<dyn CoreCloudService>,
Arc<dyn WorkspaceCloudService>,
) {
let user: Arc<dyn WorkspaceUser> = Arc::new(WorkspaceUserImpl(user_session.clone()));
let database: Arc<dyn WorkspaceDatabase> = Arc::new(WorkspaceDatabaseImpl(user_session));
@ -58,7 +58,7 @@ impl WorkspaceUser for WorkspaceUserImpl {
fn token(&self) -> Result<String, FlowyError> { self.0.token().map_err(|e| FlowyError::internal().context(e)) }
}
fn make_core_cloud_service(config: &ClientServerConfiguration) -> Arc<dyn CoreCloudService> {
fn make_core_cloud_service(config: &ClientServerConfiguration) -> Arc<dyn WorkspaceCloudService> {
if cfg!(feature = "http_server") {
Arc::new(CoreHttpCloudServiceAdaptor::new(config))
} else {
@ -70,19 +70,8 @@ struct CoreHttpCloudServiceAdaptor(CoreHttpCloudService);
impl CoreHttpCloudServiceAdaptor {
fn new(config: &ClientServerConfiguration) -> Self { Self(CoreHttpCloudService::new(config.clone())) }
}
impl CoreCloudService for CoreHttpCloudServiceAdaptor {
fn init(&self) {
// let mut rx = BACKEND_API_MIDDLEWARE.invalid_token_subscribe();
// tokio::spawn(async move {
// while let Ok(invalid_token) = rx.recv().await {
// let error = FlowyError::new(ErrorCode::UserUnauthorized, "");
// send_dart_notification(&invalid_token,
// WorkspaceNotification::UserUnauthorized) .error(error)
// .send()
// }
// });
self.0.init()
}
impl WorkspaceCloudService for CoreHttpCloudServiceAdaptor {
fn init(&self) { self.0.init() }
fn create_workspace(&self, token: &str, params: CreateWorkspaceParams) -> FutureResult<Workspace, FlowyError> {
self.0.create_workspace(token, params)
@ -148,7 +137,7 @@ impl CoreLocalCloudServiceAdaptor {
fn new(config: &ClientServerConfiguration) -> Self { Self(CoreLocalCloudService::new(config)) }
}
impl CoreCloudService for CoreLocalCloudServiceAdaptor {
impl WorkspaceCloudService for CoreLocalCloudServiceAdaptor {
fn init(&self) { self.0.init() }
fn create_workspace(&self, token: &str, params: CreateWorkspaceParams) -> FutureResult<Workspace, FlowyError> {

View File

@ -15,7 +15,7 @@ use flowy_net::{
cloud::document::{DocumentHttpCloudService, DocumentLocalCloudService},
services::ws_conn::FlowyWebSocketConnect,
};
use flowy_user::services::user::UserSession;
use flowy_user::services::UserSession;
use lib_infra::future::FutureResult;
use lib_ws::{WSMessageReceiver, WSModule, WebSocketRawMessage};
use std::{convert::TryInto, path::Path, sync::Arc};

View File

@ -11,10 +11,7 @@ use flowy_net::{
ws_conn::{listen_on_websocket, FlowyRawWebSocket, FlowyWebSocketConnect},
},
};
use flowy_user::{
entities::UserStatus,
services::user::{UserSession, UserSessionConfig},
};
use flowy_user::services::{notifier::UserStatus, UserSession, UserSessionConfig};
use lib_dispatch::prelude::*;
use lib_ws::WSController;
use module::mk_modules;

View File

@ -1,6 +1,6 @@
use flowy_core::context::CoreContext;
use flowy_net::services::ws_conn::FlowyWebSocketConnect;
use flowy_user::services::user::UserSession;
use flowy_user::services::UserSession;
use lib_dispatch::prelude::Module;
use std::sync::Arc;

View File

@ -15,6 +15,7 @@ use flowy_user::{
errors::FlowyError,
event::UserEvent::{InitUser, SignIn, SignOut, SignUp},
};
use lib_dispatch::prelude::{EventDispatcher, ModuleRequest, ToBytes};
use lib_infra::uuid_string;
use std::{fs, path::PathBuf, sync::Arc};

View File

@ -1,4 +0,0 @@
mod status;
pub use flowy_user_data_model::entities::*;
pub use status::*;

View File

@ -1,20 +0,0 @@
use crate::entities::UserProfile;
use tokio::sync::mpsc;
#[derive(Clone)]
pub enum UserStatus {
Login {
token: String,
user_id: String,
},
Logout {
token: String,
},
Expired {
token: String,
},
SignUp {
profile: UserProfile,
ret: mpsc::Sender<()>,
},
}

View File

@ -1,4 +1,6 @@
use crate::{entities::*, errors::FlowyError, services::user::UserSession};
use crate::services::UserSession;
use flowy_error::FlowyError;
use flowy_user_data_model::entities::*;
use lib_dispatch::prelude::*;
use std::{convert::TryInto, sync::Arc};

View File

@ -1,5 +1,5 @@
use crate::{entities::*, errors::FlowyError, services::user::UserSession};
use crate::{errors::FlowyError, services::UserSession};
use flowy_user_data_model::entities::*;
use lib_dispatch::prelude::*;
use std::{convert::TryInto, sync::Arc};

View File

@ -1,11 +1,10 @@
pub mod entities;
pub mod event;
mod handlers;
pub mod module;
pub mod notify;
pub mod protobuf;
pub mod services;
mod sql_tables;
// mod sql_tables;
#[macro_use]
extern crate flowy_database;
@ -13,3 +12,7 @@ extern crate flowy_database;
pub mod errors {
pub use flowy_error::{internal_error, ErrorCode, FlowyError};
}
pub mod entities {
pub use flowy_user_data_model::entities::*;
}

View File

@ -1,12 +1,13 @@
use lib_dispatch::prelude::*;
use crate::{
entities::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserParams, UserProfile},
errors::FlowyError,
event::UserEvent,
handlers::*,
services::user::UserSession,
use crate::{errors::FlowyError, event::UserEvent, handlers::*, services::UserSession};
use flowy_user_data_model::entities::{
SignInParams,
SignInResponse,
SignUpParams,
SignUpResponse,
UpdateUserParams,
UserProfile,
};
use lib_dispatch::prelude::*;
use lib_infra::future::FutureResult;
use std::sync::Arc;

View File

@ -1,10 +1,12 @@
use crate::errors::FlowyError;
use flowy_database::{DBConnection, Database};
use flowy_database::{schema::user_table, DBConnection, Database};
use flowy_error::FlowyError;
use flowy_user_data_model::entities::{SignInResponse, SignUpResponse, UpdateUserParams, UserProfile};
use lazy_static::lazy_static;
use lib_sqlite::ConnectionPool;
use once_cell::sync::Lazy;
use parking_lot::{Mutex, RwLock};
use std::{collections::HashMap, sync::Arc, time::Duration};
lazy_static! {
static ref DB: RwLock<Option<Database>> = RwLock::new(None);
}
@ -100,11 +102,68 @@ fn is_user_db_init(user_id: &str) -> bool {
}
}
#[cfg(test)]
mod tests {
#[derive(Clone, Default, Queryable, Identifiable, Insertable)]
#[table_name = "user_table"]
pub struct UserTable {
pub(crate) id: String,
pub(crate) name: String,
pub(crate) token: String,
pub(crate) email: String,
pub(crate) workspace: String, // deprecated
}
#[test]
fn init_db_test() {
// init_user_db(".").unwrap();
impl UserTable {
pub fn new(id: String, name: String, email: String, token: String) -> Self {
Self {
id,
name,
email,
token,
workspace: "".to_owned(),
}
}
pub fn set_workspace(mut self, workspace: String) -> Self {
self.workspace = workspace;
self
}
}
impl std::convert::From<SignUpResponse> for UserTable {
fn from(resp: SignUpResponse) -> Self { UserTable::new(resp.user_id, resp.name, resp.email, resp.token) }
}
impl std::convert::From<SignInResponse> for UserTable {
fn from(resp: SignInResponse) -> Self { UserTable::new(resp.user_id, resp.name, resp.email, resp.token) }
}
impl std::convert::From<UserTable> for UserProfile {
fn from(table: UserTable) -> Self {
UserProfile {
id: table.id,
email: table.email,
name: table.name,
token: table.token,
}
}
}
#[derive(AsChangeset, Identifiable, Default, Debug)]
#[table_name = "user_table"]
pub struct UserTableChangeset {
pub id: String,
pub workspace: Option<String>, // deprecated
pub name: Option<String>,
pub email: Option<String>,
}
impl UserTableChangeset {
pub fn new(params: UpdateUserParams) -> Self {
UserTableChangeset {
id: params.id,
workspace: None,
name: params.name,
email: params.email,
}
}
}

View File

@ -1 +1,4 @@
pub mod user;
mod database;
pub mod notifier;
mod user_session;
pub use user_session::*;

View File

@ -1,7 +1,24 @@
use crate::entities::{UserProfile, UserStatus};
use flowy_user_data_model::entities::UserProfile;
use tokio::sync::{broadcast, mpsc};
#[derive(Clone)]
pub enum UserStatus {
Login {
token: String,
user_id: String,
},
Logout {
token: String,
},
Expired {
token: String,
},
SignUp {
profile: UserProfile,
ret: mpsc::Sender<()>,
},
}
pub struct UserNotifier {
user_status_notifier: broadcast::Sender<UserStatus>,
}

View File

@ -1,5 +0,0 @@
pub use user_session::*;
pub mod database;
mod notifier;
mod user_session;

View File

@ -1,3 +1,12 @@
use crate::{
errors::{ErrorCode, FlowyError},
module::UserCloudService,
notify::*,
services::{
database::{UserDB, UserTable, UserTableChangeset},
notifier::UserNotifier,
},
};
use flowy_database::{
kv::KV,
query_dsl::*,
@ -6,22 +15,20 @@ use flowy_database::{
ExpressionMethods,
UserDatabaseConnection,
};
use flowy_user_data_model::entities::{SignInResponse, SignUpResponse};
use flowy_user_data_model::entities::{
SignInParams,
SignInResponse,
SignUpParams,
SignUpResponse,
UpdateUserParams,
UserProfile,
};
use lib_sqlite::ConnectionPool;
use parking_lot::RwLock;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tokio::sync::mpsc;
use crate::{
entities::{SignInParams, SignUpParams, UpdateUserParams, UserProfile},
errors::{ErrorCode, FlowyError},
module::UserCloudService,
notify::*,
services::user::{database::UserDB, notifier::UserNotifier},
sql_tables::{UserTable, UserTableChangeset},
};
pub struct UserSessionConfig {
root_dir: String,
session_cache_key: String,

View File

@ -1,3 +0,0 @@
mod user;
pub use user::*;

View File

@ -1,69 +0,0 @@
use crate::entities::{SignInResponse, SignUpResponse, UpdateUserParams};
use flowy_database::schema::user_table;
use flowy_user_data_model::entities::UserProfile;
#[derive(Clone, Default, Queryable, Identifiable, Insertable)]
#[table_name = "user_table"]
pub struct UserTable {
pub(crate) id: String,
pub(crate) name: String,
pub(crate) token: String,
pub(crate) email: String,
pub(crate) workspace: String, // deprecated
}
impl UserTable {
pub fn new(id: String, name: String, email: String, token: String) -> Self {
Self {
id,
name,
email,
token,
workspace: "".to_owned(),
}
}
pub fn set_workspace(mut self, workspace: String) -> Self {
self.workspace = workspace;
self
}
}
impl std::convert::From<SignUpResponse> for UserTable {
fn from(resp: SignUpResponse) -> Self { UserTable::new(resp.user_id, resp.name, resp.email, resp.token) }
}
impl std::convert::From<SignInResponse> for UserTable {
fn from(resp: SignInResponse) -> Self { UserTable::new(resp.user_id, resp.name, resp.email, resp.token) }
}
impl std::convert::From<UserTable> for UserProfile {
fn from(table: UserTable) -> Self {
UserProfile {
id: table.id,
email: table.email,
name: table.name,
token: table.token,
}
}
}
#[derive(AsChangeset, Identifiable, Default, Debug)]
#[table_name = "user_table"]
pub struct UserTableChangeset {
pub id: String,
pub workspace: Option<String>, // deprecated
pub name: Option<String>,
pub email: Option<String>,
}
impl UserTableChangeset {
pub fn new(params: UpdateUserParams) -> Self {
UserTableChangeset {
id: params.id,
workspace: None,
name: params.name,
email: params.email,
}
}
}