diff --git a/frontend/app_flowy/lib/user/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/user/infrastructure/deps_resolver.dart index be1e7461a0..1d3bedb833 100644 --- a/frontend/app_flowy/lib/user/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/user/infrastructure/deps_resolver.dart @@ -5,9 +5,6 @@ import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; import 'package:app_flowy/user/infrastructure/router.dart'; import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart'; import 'package:app_flowy/workspace/application/home/home_bloc.dart'; -import 'package:app_flowy/workspace/application/home/home_listen_bloc.dart'; -import 'package:app_flowy/workspace/domain/i_user.dart'; -import 'package:app_flowy/workspace/infrastructure/i_user_impl.dart'; import 'package:get_it/get_it.dart'; import 'network_monitor.dart'; @@ -27,11 +24,6 @@ class UserDepsResolver { getIt.registerFactory(() => HomeBloc()); getIt.registerFactory(() => EditPannelBloc()); getIt.registerFactory(() => SplashBloc()); - - getIt.registerFactoryParam((user, _) => HomeListenBloc( - getIt(param1: user), - )); - getIt.registerLazySingleton(() => NetworkMonitor()); } } diff --git a/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart b/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart index cab4f4db38..ffc88bc101 100644 --- a/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart @@ -1,7 +1,7 @@ import 'package:app_flowy/user/infrastructure/router.dart'; import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; import 'package:app_flowy/user/presentation/widgets/background.dart'; -import 'package:app_flowy/workspace/domain/i_user.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_infra/size.dart'; import 'package:flowy_infra/theme.dart'; @@ -12,6 +12,7 @@ import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -33,7 +34,7 @@ class SkipLogInScreen extends StatefulWidget { } class _SkipLogInScreenState extends State { - IUserListener? userListener; + UserListener? userListener; @override Widget build(BuildContext context) { diff --git a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart index 4be21331b7..932308efdb 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart @@ -11,7 +11,7 @@ part 'app_bloc.freezed.dart'; class AppBloc extends Bloc { final AppRepository repo; - final AppListenerRepository listener; + final AppListener listener; AppBloc({required App app, required this.repo, required this.listener}) : super(AppState.initial(app)) { on((event, emit) async { await event.map(initial: (e) async { diff --git a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart index 7327987610..8526ad8c59 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart @@ -1,14 +1,13 @@ import 'dart:convert'; - -import 'package:app_flowy/workspace/domain/i_trash.dart'; -import 'package:app_flowy/workspace/domain/i_view.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flutter_quill/flutter_quill.dart'; import 'package:flowy_log/flowy_log.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:app_flowy/workspace/domain/i_doc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:dartz/dartz.dart'; import 'dart:async'; @@ -16,17 +15,17 @@ part 'doc_bloc.freezed.dart'; class DocBloc extends Bloc { final View view; - final IDoc docManager; - final IViewListener listener; - final ITrash trasnManager; + final DocRepository repo; + final ViewListener listener; + final TrashRepo trashRepo; late Document document; StreamSubscription? _subscription; DocBloc({ required this.view, - required this.docManager, + required this.repo, required this.listener, - required this.trasnManager, + required this.trashRepo, }) : super(DocState.initial()) { on((event, emit) async { await event.map( @@ -40,12 +39,12 @@ class DocBloc extends Bloc { emit(state.copyWith(isDeleted: false)); }, deletePermanently: (DeletePermanently value) async { - final result = await trasnManager.deleteViews([Tuple2(view.id, TrashType.View)]); + final result = await trashRepo.deleteViews([Tuple2(view.id, TrashType.View)]); final newState = result.fold((l) => state.copyWith(forceClose: true), (r) => state); emit(newState); }, restorePage: (RestorePage value) async { - final result = await trasnManager.putback(view.id); + final result = await trashRepo.putback(view.id); final newState = result.fold((l) => state.copyWith(isDeleted: false), (r) => state); emit(newState); }, @@ -55,13 +54,13 @@ class DocBloc extends Bloc { @override Future close() async { - await listener.stop(); + await listener.close(); if (_subscription != null) { await _subscription?.cancel(); } - docManager.closeDoc(); + repo.closeDoc(); return super.close(); } @@ -81,7 +80,7 @@ class DocBloc extends Bloc { }); listener.start(); - final result = await docManager.readDoc(); + final result = await repo.readDoc(); result.fold( (doc) { document = _decodeJsonToDocument(doc.deltaJson); @@ -107,7 +106,7 @@ class DocBloc extends Bloc { void _composeDelta(Delta composedDelta, Delta documentDelta) async { final json = jsonEncode(composedDelta.toJson()); Log.debug("doc_id: $view.id - Send json: $json"); - final result = await docManager.composeDelta(json: json); + final result = await repo.composeDelta(data: json); result.fold((rustDoc) { // final json = utf8.decode(doc.data); diff --git a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart index 6053525aad..460a9986c7 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart @@ -1,5 +1,5 @@ -import 'package:app_flowy/workspace/domain/i_share.dart'; import 'package:app_flowy/workspace/infrastructure/markdown/delta_markdown.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/share_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/share.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; @@ -9,13 +9,13 @@ import 'package:dartz/dartz.dart'; part 'share_bloc.freezed.dart'; class DocShareBloc extends Bloc { - IShare shareManager; + ShareRepo repo; View view; - DocShareBloc({required this.view, required this.shareManager}) : super(const DocShareState.initial()) { + DocShareBloc({required this.view, required this.repo}) : super(const DocShareState.initial()) { on((event, emit) async { await event.map( shareMarkdown: (ShareMarkdown value) async { - await shareManager.exportMarkdown(view.id).then((result) { + await repo.exportMarkdown(view.id).then((result) { result.fold( (value) => emit(DocShareState.finish(left(_convertDeltaToMarkdown(value)))), (error) => emit(DocShareState.finish(right(error))), diff --git a/frontend/app_flowy/lib/workspace/application/home/home_listen_bloc.dart b/frontend/app_flowy/lib/workspace/application/home/home_listen_bloc.dart index 3435b537d8..5285c067df 100644 --- a/frontend/app_flowy/lib/workspace/application/home/home_listen_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/home/home_listen_bloc.dart @@ -1,4 +1,4 @@ -import 'package:app_flowy/workspace/domain/i_user.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -7,7 +7,7 @@ import 'package:dartz/dartz.dart'; part 'home_listen_bloc.freezed.dart'; class HomeListenBloc extends Bloc { - final IUserListener listener; + final UserListener listener; HomeListenBloc(this.listener) : super(const HomeListenState.loading()) { on((event, emit) async { await event.map( diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart index 599023dcde..c2f73c62d8 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart @@ -1,7 +1,8 @@ -import 'package:app_flowy/workspace/domain/i_user.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:dartz/dartz.dart'; @@ -9,10 +10,10 @@ import 'package:dartz/dartz.dart'; part 'menu_user_bloc.freezed.dart'; class MenuUserBloc extends Bloc { - final IUser userManager; - final IUserListener listener; + final UserRepo repo; + final UserListener listener; - MenuUserBloc(this.userManager, this.listener) : super(MenuUserState.initial(userManager.user)) { + MenuUserBloc(this.repo, this.listener) : super(MenuUserState.initial(repo.user)) { on((event, emit) async { await event.map( initial: (_) async { @@ -33,7 +34,7 @@ class MenuUserBloc extends Bloc { } Future _initUser() async { - final result = await userManager.initUser(); + final result = await repo.initUser(); result.fold((l) => null, (error) => Log.error(error)); } diff --git a/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart index dd2bac1861..49d86f71a9 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart @@ -1,4 +1,4 @@ -import 'package:app_flowy/workspace/domain/i_trash.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; @@ -8,30 +8,30 @@ import 'package:freezed_annotation/freezed_annotation.dart'; part 'trash_bloc.freezed.dart'; class TrashBloc extends Bloc { - final ITrash trasnManager; - final ITrashListener listener; - TrashBloc({required this.trasnManager, required this.listener}) : super(TrashState.init()) { + final TrashRepo repo; + final TrashListener listener; + TrashBloc({required this.repo, required this.listener}) : super(TrashState.init()) { on((event, emit) async { await event.map(initial: (e) async { - listener.start(_listenTrashUpdated); - final result = await trasnManager.readTrash(); + listener.startListening(trashUpdated: _listenTrashUpdated); + final result = await repo.readTrash(); emit(result.fold( - (objects) => state.copyWith(objects: objects, successOrFailure: left(unit)), + (object) => state.copyWith(objects: object.items, successOrFailure: left(unit)), (error) => state.copyWith(successOrFailure: right(error)), )); }, didReceiveTrash: (e) async { emit(state.copyWith(objects: e.trash)); }, putback: (e) async { - final result = await trasnManager.putback(e.trashId); + final result = await repo.putback(e.trashId); await _handleResult(result, emit); }, delete: (e) async { - final result = await trasnManager.deleteViews([Tuple2(e.trash.id, e.trash.ty)]); + final result = await repo.deleteViews([Tuple2(e.trash.id, e.trash.ty)]); await _handleResult(result, emit); }, deleteAll: (e) async { - final result = await trasnManager.deleteAll(); + final result = await repo.deleteAll(); await _handleResult(result, emit); }, restoreAll: (e) async { - final result = await trasnManager.restoreAll(); + final result = await repo.restoreAll(); await _handleResult(result, emit); }); }); @@ -57,7 +57,7 @@ class TrashBloc extends Bloc { @override Future close() async { - await listener.stop(); + await listener.close(); return super.close(); } } diff --git a/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart b/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart index 11a9805d9e..4bdc939e9a 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart @@ -1,20 +1,21 @@ +import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:app_flowy/workspace/domain/i_view.dart'; part 'view_bloc.freezed.dart'; class ViewBloc extends Bloc { - final IView viewManager; - final IViewListener listener; + final ViewRepository repo; + + final ViewListener listener; ViewBloc({ - required this.viewManager, + required this.repo, required this.listener, - }) : super(ViewState.init(viewManager.view)) { + }) : super(ViewState.init(repo.view)) { on((event, emit) async { await event.map( initial: (e) { @@ -36,7 +37,7 @@ class ViewBloc extends Bloc { ); }, rename: (e) async { - final result = await viewManager.rename(e.newName); + final result = await repo.updateView(name: e.newName); emit( result.fold( (l) => state.copyWith(successOrFailure: left(unit)), @@ -45,7 +46,7 @@ class ViewBloc extends Bloc { ); }, delete: (e) async { - final result = await viewManager.delete(); + final result = await repo.delete(); emit( result.fold( (l) => state.copyWith(successOrFailure: left(unit)), @@ -54,7 +55,7 @@ class ViewBloc extends Bloc { ); }, duplicate: (e) async { - final result = await viewManager.duplicate(); + final result = await repo.duplicate(); emit( result.fold( (l) => state.copyWith(successOrFailure: left(unit)), @@ -68,7 +69,7 @@ class ViewBloc extends Bloc { @override Future close() async { - await listener.stop(); + await listener.close(); return super.close(); } } diff --git a/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart b/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart index c180aeb298..3f6a770724 100644 --- a/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart @@ -1,4 +1,3 @@ -import 'package:app_flowy/workspace/domain/i_user.dart'; import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; @@ -11,7 +10,7 @@ part 'welcome_bloc.freezed.dart'; class WelcomeBloc extends Bloc { final UserRepo repo; - final IUserListener listener; + final UserListener listener; WelcomeBloc({required this.repo, required this.listener}) : super(WelcomeState.initial()) { on( (event, emit) async { diff --git a/frontend/app_flowy/lib/workspace/domain/i_doc.dart b/frontend/app_flowy/lib/workspace/domain/i_doc.dart deleted file mode 100644 index c0653e2124..0000000000 --- a/frontend/app_flowy/lib/workspace/domain/i_doc.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'dart:async'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-collaboration/document_info.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -abstract class IDoc { - Future> readDoc(); - Future> composeDelta({required String json}); - Future> closeDoc(); -} diff --git a/frontend/app_flowy/lib/workspace/domain/i_share.dart b/frontend/app_flowy/lib/workspace/domain/i_share.dart deleted file mode 100644 index fa4b1c4853..0000000000 --- a/frontend/app_flowy/lib/workspace/domain/i_share.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'dart:async'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -abstract class IShare { - Future> exportText(String docId); - - Future> exportMarkdown(String docId); - - Future> exportURL(String docId); -} diff --git a/frontend/app_flowy/lib/workspace/domain/i_trash.dart b/frontend/app_flowy/lib/workspace/domain/i_trash.dart deleted file mode 100644 index dadff00009..0000000000 --- a/frontend/app_flowy/lib/workspace/domain/i_trash.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'dart:async'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -abstract class ITrash { - Future, FlowyError>> readTrash(); - - Future> putback(String trashId); - - Future> deleteViews(List> trashList); - - Future> restoreAll(); - - Future> deleteAll(); -} - -typedef TrashUpdatedCallback = void Function(Either, FlowyError> trashOrFailed); - -abstract class ITrashListener { - void start(TrashUpdatedCallback updateCallback); - Future stop(); -} diff --git a/frontend/app_flowy/lib/workspace/domain/i_user.dart b/frontend/app_flowy/lib/workspace/domain/i_user.dart deleted file mode 100644 index c43aaa1857..0000000000 --- a/frontend/app_flowy/lib/workspace/domain/i_user.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:dartz/dartz.dart'; -import 'package:flowy_infra/notifier.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; -export 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile; - -abstract class IUser { - UserProfile get user; - Future> fetchUserProfile(String userId); - Future, FlowyError>> fetchWorkspaces(); - Future> deleteWorkspace(String workspaceId); - Future> signOut(); - Future> initUser(); -} - -typedef UserProfileUpdatedNotifierValue = Either; -typedef AuthNotifierValue = Either; -typedef WorkspaceUpdatedNotifierValue = Either, FlowyError>; - -abstract class IUserListener { - void start(); - - PublishNotifier get profileUpdatedNotifier; - PublishNotifier get authDidChangedNotifier; - PublishNotifier get workspaceUpdatedNotifier; - - Future stop(); -} diff --git a/frontend/app_flowy/lib/workspace/domain/i_view.dart b/frontend/app_flowy/lib/workspace/domain/i_view.dart deleted file mode 100644 index 4e56fbaeb0..0000000000 --- a/frontend/app_flowy/lib/workspace/domain/i_view.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_infra/notifier.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -typedef ViewUpdatedCallback = void Function(Either); - -typedef DeleteNotifierValue = Either; -typedef UpdateNotifierValue = Either; -typedef RestoreNotifierValue = Either; - -abstract class IView { - View get view; - - Future> delete(); - - Future> rename(String newName); - - Future> duplicate(); -} - -abstract class IViewListener { - void start(); - - PublishNotifier get updatedNotifier; - - PublishNotifier get deletedNotifier; - - PublishNotifier get restoredNotifier; - - Future stop(); -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 7c067a3d14..f902c9607a 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -1,40 +1,41 @@ import 'package:app_flowy/workspace/application/app/app_bloc.dart'; import 'package:app_flowy/workspace/application/doc/doc_bloc.dart'; import 'package:app_flowy/workspace/application/doc/share_bloc.dart'; +import 'package:app_flowy/workspace/application/home/home_listen_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart'; import 'package:app_flowy/workspace/application/trash/trash_bloc.dart'; import 'package:app_flowy/workspace/application/view/view_bloc.dart'; import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart'; -import 'package:app_flowy/workspace/domain/i_doc.dart'; -import 'package:app_flowy/workspace/domain/i_share.dart'; -import 'package:app_flowy/workspace/domain/i_trash.dart'; -import 'package:app_flowy/workspace/domain/i_view.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; -import 'package:app_flowy/workspace/infrastructure/i_doc_impl.dart'; -import 'package:app_flowy/workspace/infrastructure/i_trash_impl.dart'; import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; import 'package:get_it/get_it.dart'; - -import 'i_share_impl.dart'; -import 'i_user_impl.dart'; -import 'i_view_impl.dart'; import 'repos/share_repo.dart'; class HomeDepsResolver { static Future resolve(GetIt getIt) async { + getIt.registerFactoryParam( + (user, _) => UserListener(user: user), + ); + + getIt.registerFactoryParam( + (user, _) => HomeListenBloc(getIt(param1: user)), + ); + // getIt.registerLazySingleton(() => HomeStackManager()); getIt.registerFactoryParam( (user, _) => WelcomeBloc( repo: UserRepo(user: user), - listener: getIt(param1: user), + listener: getIt(param1: user), ), ); @@ -43,22 +44,16 @@ class HomeDepsResolver { (user, workspaceId) => WorkspaceListener(repo: WorkspaceListenerRepo(user: user, workspaceId: workspaceId))); // View - getIt.registerFactoryParam((view, _) => IViewImpl(repo: ViewRepository(view: view))); - getIt.registerFactoryParam( - (view, _) => IViewListenerImpl(repo: ViewListenerRepository(view: view))); - getIt.registerFactoryParam( - (view, _) => ViewBloc( - viewManager: getIt(param1: view), - listener: getIt(param1: view), - ), + getIt.registerFactoryParam( + (view, _) => ViewListener(view: view), ); - // Doc - getIt.registerFactoryParam((docId, _) => IDocImpl(repo: DocRepository(docId: docId))); - - // User - getIt.registerFactoryParam((user, _) => IUserImpl(repo: UserRepo(user: user))); - getIt.registerFactoryParam((user, _) => IUserListenerImpl(user: user)); + getIt.registerFactoryParam( + (view, _) => ViewBloc( + repo: ViewRepository(view: view), + listener: getIt(param1: view), + ), + ); //Menu Bloc getIt.registerFactoryParam( @@ -69,14 +64,18 @@ class HomeDepsResolver { ); getIt.registerFactoryParam( - (user, _) => MenuUserBloc(getIt(param1: user), getIt(param1: user))); + (user, _) => MenuUserBloc( + UserRepo(user: user), + getIt(param1: user), + ), + ); // App getIt.registerFactoryParam( (app, _) => AppBloc( app: app, repo: AppRepository(appId: app.id), - listener: AppListenerRepository(appId: app.id), + listener: AppListener(appId: app.id), ), ); @@ -84,23 +83,25 @@ class HomeDepsResolver { getIt.registerFactoryParam( (view, _) => DocBloc( view: view, - docManager: getIt(param1: view.id), - listener: getIt(param1: view), - trasnManager: getIt(), + repo: DocRepository(docId: view.id), + listener: getIt(param1: view), + trashRepo: getIt(), ), ); // trash getIt.registerLazySingleton(() => TrashRepo()); - getIt.registerLazySingleton(() => TrashListenerRepo()); - getIt.registerFactory(() => ITrashImpl(repo: getIt())); - getIt.registerFactory(() => ITrashListenerImpl(repo: getIt())); - getIt.registerFactory(() => TrashBloc(trasnManager: getIt(), listener: getIt())); + getIt.registerLazySingleton(() => TrashListener()); + getIt.registerFactory( + () => TrashBloc( + repo: getIt(), + listener: getIt(), + ), + ); // share getIt.registerLazySingleton(() => ShareRepo()); - getIt.registerFactory(() => IShareImpl(repo: getIt())); getIt.registerFactoryParam( - (view, _) => DocShareBloc(view: view, shareManager: getIt())); + (view, _) => DocShareBloc(view: view, repo: getIt())); } } diff --git a/frontend/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart b/frontend/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart deleted file mode 100644 index d78400459b..0000000000 --- a/frontend/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:dartz/dartz.dart'; -import 'package:app_flowy/workspace/domain/i_doc.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart'; -import 'package:flowy_sdk/protobuf/flowy-collaboration/document_info.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -class IDocImpl extends IDoc { - DocRepository repo; - - IDocImpl({required this.repo}); - - @override - Future> closeDoc() { - return repo.closeDoc(); - } - - @override - Future> readDoc() async { - final docOrFail = await repo.readDoc(); - return docOrFail; - } - - @override - Future> composeDelta({required String json}) { - return repo.composeDelta(data: json); - } -} - -// ignore: unused_element -Uint8List _encodeJsonText(String? json) { - final data = utf8.encode(json ?? ""); - return Uint8List.fromList(data); -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/i_share_impl.dart b/frontend/app_flowy/lib/workspace/infrastructure/i_share_impl.dart deleted file mode 100644 index cfd484399f..0000000000 --- a/frontend/app_flowy/lib/workspace/infrastructure/i_share_impl.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'package:app_flowy/workspace/domain/i_share.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:dartz/dartz.dart'; - -import 'repos/share_repo.dart'; - -class IShareImpl extends IShare { - ShareRepo repo; - - IShareImpl({required this.repo}); - - @override - Future> exportText(String docId) { - return repo.export(docId, ExportType.Text); - } - - @override - Future> exportMarkdown(String docId) { - return repo.export(docId, ExportType.Markdown); - } - - @override - Future> exportURL(String docId) { - return repo.export(docId, ExportType.Link); - } -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart b/frontend/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart deleted file mode 100644 index 2e822e2609..0000000000 --- a/frontend/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'package:app_flowy/workspace/domain/i_trash.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -class ITrashImpl implements ITrash { - TrashRepo repo; - - ITrashImpl({required this.repo}); - - @override - Future, FlowyError>> readTrash() { - return repo.readTrash().then((result) { - return result.fold( - (repeatedTrash) => left(repeatedTrash.items), - (err) => right(err), - ); - }); - } - - @override - Future> putback(String trashId) { - return repo.putback(trashId); - } - - @override - Future> deleteAll() { - return repo.deleteAll(); - } - - @override - Future> restoreAll() { - return repo.restoreAll(); - } - - @override - Future> deleteViews(List> trashList) { - return repo.deleteViews(trashList); - } -} - -class ITrashListenerImpl extends ITrashListener { - TrashListenerRepo repo; - ITrashListenerImpl({ - required this.repo, - }); - - @override - Future stop() async { - await repo.close(); - } - - @override - void start(TrashUpdatedCallback updateCallback) { - repo.startListening(trashUpdated: updateCallback); - } -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/i_user_impl.dart b/frontend/app_flowy/lib/workspace/infrastructure/i_user_impl.dart deleted file mode 100644 index 1aab9e6d02..0000000000 --- a/frontend/app_flowy/lib/workspace/infrastructure/i_user_impl.dart +++ /dev/null @@ -1,127 +0,0 @@ -import 'dart:typed_data'; - -import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; -import 'package:dartz/dartz.dart'; -import 'package:app_flowy/workspace/domain/i_user.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; -import 'package:flowy_infra/notifier.dart'; -import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-user-data-model/errors.pb.dart'; -// import 'package:flowy_sdk/protobuf/flowy-user/errors.pb.dart' as user_error; -import 'package:flowy_sdk/protobuf/flowy-user/dart_notification.pb.dart' as user; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -export 'package:app_flowy/workspace/domain/i_user.dart'; -export 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; -import 'package:flowy_sdk/rust_stream.dart'; -import 'dart:async'; - -class IUserImpl extends IUser { - UserRepo repo; - IUserImpl({ - required this.repo, - }); - - @override - Future> deleteWorkspace(String workspaceId) { - return repo.deleteWorkspace(workspaceId: workspaceId); - } - - @override - Future> fetchUserProfile(String userId) { - return repo.fetchUserProfile(userId: userId); - } - - @override - Future> signOut() { - return repo.signOut(); - } - - @override - UserProfile get user => repo.user; - - @override - Future, FlowyError>> fetchWorkspaces() { - return repo.getWorkspaces(); - } - - @override - Future> initUser() { - return repo.initUser(); - } -} - -class IUserListenerImpl extends IUserListener { - StreamSubscription? _subscription; - - @override - final profileUpdatedNotifier = PublishNotifier(); - - @override - final authDidChangedNotifier = PublishNotifier(); - - @override - final workspaceUpdatedNotifier = PublishNotifier(); - - late FolderNotificationParser _workspaceParser; - late UserNotificationParser _userParser; - late UserProfile _user; - IUserListenerImpl({ - required UserProfile user, - }) { - _user = user; - } - - @override - void start() { - _workspaceParser = FolderNotificationParser(id: _user.token, callback: _notificationCallback); - _userParser = UserNotificationParser(id: _user.token, callback: _userNotificationCallback); - _subscription = RustStreamReceiver.listen((observable) { - _workspaceParser.parse(observable); - _userParser.parse(observable); - }); - } - - @override - Future stop() async { - await _subscription?.cancel(); - profileUpdatedNotifier.dispose(); - authDidChangedNotifier.dispose(); - workspaceUpdatedNotifier.dispose(); - } - - void _notificationCallback(FolderNotification ty, Either result) { - switch (ty) { - case FolderNotification.UserCreateWorkspace: - case FolderNotification.UserDeleteWorkspace: - case FolderNotification.WorkspaceListUpdated: - result.fold( - (payload) => workspaceUpdatedNotifier.value = left(RepeatedWorkspace.fromBuffer(payload).items), - (error) => workspaceUpdatedNotifier.value = right(error), - ); - break; - case FolderNotification.UserUnauthorized: - result.fold( - (_) {}, - (error) => authDidChangedNotifier.value = right(FlowyError.create()..code = ErrorCode.UserUnauthorized.value), - ); - break; - default: - break; - } - } - - void _userNotificationCallback(user.UserNotification ty, Either result) { - switch (ty) { - case user.UserNotification.UserUnauthorized: - result.fold( - (payload) => profileUpdatedNotifier.value = left(UserProfile.fromBuffer(payload)), - (error) => profileUpdatedNotifier.value = right(error), - ); - break; - default: - break; - } - } -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/i_view_impl.dart b/frontend/app_flowy/lib/workspace/infrastructure/i_view_impl.dart deleted file mode 100644 index 466fa563d7..0000000000 --- a/frontend/app_flowy/lib/workspace/infrastructure/i_view_impl.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'package:app_flowy/workspace/domain/i_view.dart'; -import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; -import 'package:flowy_infra/notifier.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; - -class IViewImpl extends IView { - ViewRepository repo; - - IViewImpl({required this.repo}); - - @override - View get view => repo.view; - - @override - Future> delete() { - return repo.delete().then((result) { - return result.fold( - (_) => left(unit), - (error) => right(error), - ); - }); - } - - @override - Future> rename(String newName) { - return repo.updateView(name: newName); - } - - @override - Future> duplicate() { - return repo.duplicate(); - } -} - -class IViewListenerImpl extends IViewListener { - final ViewListenerRepository repo; - IViewListenerImpl({ - required this.repo, - }); - - @override - void start() { - repo.start(); - } - - @override - Future stop() async { - await repo.close(); - } - - @override - PublishNotifier get deletedNotifier => repo.deletedNotifier; - - @override - PublishNotifier get updatedNotifier => repo.updatedNotifier; - - @override - PublishNotifier get restoredNotifier => repo.restoredNotifier; -} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart b/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart index 0077f718eb..fd36057678 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart @@ -66,14 +66,14 @@ class AppRepository { typedef AppDidUpdateCallback = void Function(App app); typedef ViewsDidChangeCallback = void Function(Either, FlowyError> viewsOrFailed); -class AppListenerRepository { +class AppListener { StreamSubscription? _subscription; ViewsDidChangeCallback? _viewsChanged; AppDidUpdateCallback? _updated; late FolderNotificationParser _parser; String appId; - AppListenerRepository({ + AppListener({ required this.appId, }); diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart b/frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart index d8bec1327a..0b4e8ff8b8 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/repos/share_repo.dart @@ -12,4 +12,16 @@ class ShareRepo { return FolderEventExportDocument(request).send(); } + + Future> exportText(String docId) { + return export(docId, ExportType.Text); + } + + Future> exportMarkdown(String docId) { + return export(docId, ExportType.Markdown); + } + + Future> exportURL(String docId) { + return export(docId, ExportType.Link); + } } diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart b/frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart index 7cff040c90..3d2d3ee5ad 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/workspace/domain/i_trash.dart'; import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; @@ -41,7 +40,9 @@ class TrashRepo { } } -class TrashListenerRepo { +typedef TrashUpdatedCallback = void Function(Either, FlowyError> trashOrFailed); + +class TrashListener { StreamSubscription? _subscription; TrashUpdatedCallback? _trashUpdated; late FolderNotificationParser _parser; diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/user_repo.dart b/frontend/app_flowy/lib/workspace/infrastructure/repos/user_repo.dart index 6c299a0854..bf0ec8dc5b 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/user_repo.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/repos/user_repo.dart @@ -2,8 +2,17 @@ import 'dart:async'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; -import 'package:app_flowy/workspace/domain/i_user.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'dart:typed_data'; +import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; +import 'package:flowy_infra/notifier.dart'; +import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-user-data-model/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; +// import 'package:flowy_sdk/protobuf/flowy-user/errors.pb.dart' as user_error; +import 'package:flowy_sdk/protobuf/flowy-user/dart_notification.pb.dart' as user; +import 'package:flowy_sdk/rust_stream.dart'; class UserRepo { final UserProfile user; @@ -60,3 +69,73 @@ class UserRepo { }); } } + +typedef UserProfileUpdatedNotifierValue = Either; +typedef AuthNotifierValue = Either; +typedef WorkspaceUpdatedNotifierValue = Either, FlowyError>; + +class UserListener { + StreamSubscription? _subscription; + final profileUpdatedNotifier = PublishNotifier(); + final authDidChangedNotifier = PublishNotifier(); + final workspaceUpdatedNotifier = PublishNotifier(); + + late FolderNotificationParser _workspaceParser; + late UserNotificationParser _userParser; + late UserProfile _user; + UserListener({ + required UserProfile user, + }) { + _user = user; + } + + void start() { + _workspaceParser = FolderNotificationParser(id: _user.token, callback: _notificationCallback); + _userParser = UserNotificationParser(id: _user.token, callback: _userNotificationCallback); + _subscription = RustStreamReceiver.listen((observable) { + _workspaceParser.parse(observable); + _userParser.parse(observable); + }); + } + + Future stop() async { + await _subscription?.cancel(); + profileUpdatedNotifier.dispose(); + authDidChangedNotifier.dispose(); + workspaceUpdatedNotifier.dispose(); + } + + void _notificationCallback(FolderNotification ty, Either result) { + switch (ty) { + case FolderNotification.UserCreateWorkspace: + case FolderNotification.UserDeleteWorkspace: + case FolderNotification.WorkspaceListUpdated: + result.fold( + (payload) => workspaceUpdatedNotifier.value = left(RepeatedWorkspace.fromBuffer(payload).items), + (error) => workspaceUpdatedNotifier.value = right(error), + ); + break; + case FolderNotification.UserUnauthorized: + result.fold( + (_) {}, + (error) => authDidChangedNotifier.value = right(FlowyError.create()..code = ErrorCode.UserUnauthorized.value), + ); + break; + default: + break; + } + } + + void _userNotificationCallback(user.UserNotification ty, Either result) { + switch (ty) { + case user.UserNotification.UserUnauthorized: + result.fold( + (payload) => profileUpdatedNotifier.value = left(UserProfile.fromBuffer(payload)), + (error) => profileUpdatedNotifier.value = right(error), + ); + break; + default: + break; + } + } +} diff --git a/frontend/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart b/frontend/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart index 1e9f02d9c7..3ee6fcaef4 100644 --- a/frontend/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart +++ b/frontend/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart @@ -7,8 +7,6 @@ import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; - -import 'package:app_flowy/workspace/domain/i_view.dart'; import 'package:flowy_infra/notifier.dart'; import 'helper.dart'; @@ -49,7 +47,11 @@ class ViewRepository { } } -class ViewListenerRepository { +typedef DeleteNotifierValue = Either; +typedef UpdateNotifierValue = Either; +typedef RestoreNotifierValue = Either; + +class ViewListener { StreamSubscription? _subscription; PublishNotifier updatedNotifier = PublishNotifier(); PublishNotifier deletedNotifier = PublishNotifier(); @@ -57,7 +59,7 @@ class ViewListenerRepository { late FolderNotificationParser _parser; View view; - ViewListenerRepository({ + ViewListener({ required this.view, }); diff --git a/frontend/app_flowy/lib/workspace/presentation/stack_page/doc/doc_stack_page.dart b/frontend/app_flowy/lib/workspace/presentation/stack_page/doc/doc_stack_page.dart index 6127ab0fc8..18fe04257b 100644 --- a/frontend/app_flowy/lib/workspace/presentation/stack_page/doc/doc_stack_page.dart +++ b/frontend/app_flowy/lib/workspace/presentation/stack_page/doc/doc_stack_page.dart @@ -1,7 +1,6 @@ import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/workspace/application/appearance.dart'; import 'package:app_flowy/workspace/application/doc/share_bloc.dart'; -import 'package:app_flowy/workspace/domain/i_view.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/domain/view_ext.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; @@ -28,11 +27,11 @@ import 'doc_page.dart'; class DocStackContext extends HomeStackContext { View _view; - late IViewListener _listener; + late ViewListener _listener; final ValueNotifier _isUpdated = ValueNotifier(0); DocStackContext({required View view, Key? key}) : _view = view { - _listener = getIt(param1: view); + _listener = getIt(param1: view); _listener.updatedNotifier.addPublishListener((result) { result.fold( (newView) { @@ -78,7 +77,7 @@ class DocStackContext extends HomeStackContext { @override void dispose() { - _listener.stop(); + _listener.close(); } }