remove redundant interfaces

This commit is contained in:
appflowy 2022-01-31 09:49:05 +08:00
parent 99cadf98d2
commit 8127e47cea
27 changed files with 196 additions and 524 deletions

View File

@ -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>(() => HomeBloc());
getIt.registerFactory<EditPannelBloc>(() => EditPannelBloc());
getIt.registerFactory<SplashBloc>(() => SplashBloc());
getIt.registerFactoryParam<HomeListenBloc, UserProfile, void>((user, _) => HomeListenBloc(
getIt<IUserListener>(param1: user),
));
getIt.registerLazySingleton<NetworkMonitor>(() => NetworkMonitor());
}
}

View File

@ -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<SkipLogInScreen> {
IUserListener? userListener;
UserListener? userListener;
@override
Widget build(BuildContext context) {

View File

@ -11,7 +11,7 @@ part 'app_bloc.freezed.dart';
class AppBloc extends Bloc<AppEvent, AppState> {
final AppRepository repo;
final AppListenerRepository listener;
final AppListener listener;
AppBloc({required App app, required this.repo, required this.listener}) : super(AppState.initial(app)) {
on<AppEvent>((event, emit) async {
await event.map(initial: (e) async {

View File

@ -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<DocEvent, DocState> {
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<DocEvent>((event, emit) async {
await event.map(
@ -40,12 +39,12 @@ class DocBloc extends Bloc<DocEvent, DocState> {
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<DocEvent, DocState> {
@override
Future<void> 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<DocEvent, DocState> {
});
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<DocEvent, DocState> {
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);

View File

@ -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<DocShareEvent, DocShareState> {
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<DocShareEvent>((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))),

View File

@ -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<HomeListenEvent, HomeListenState> {
final IUserListener listener;
final UserListener listener;
HomeListenBloc(this.listener) : super(const HomeListenState.loading()) {
on<HomeListenEvent>((event, emit) async {
await event.map(

View File

@ -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<MenuUserEvent, MenuUserState> {
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<MenuUserEvent>((event, emit) async {
await event.map(
initial: (_) async {
@ -33,7 +34,7 @@ class MenuUserBloc extends Bloc<MenuUserEvent, MenuUserState> {
}
Future<void> _initUser() async {
final result = await userManager.initUser();
final result = await repo.initUser();
result.fold((l) => null, (error) => Log.error(error));
}

View File

@ -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<TrashEvent, TrashState> {
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<TrashEvent>((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<TrashEvent, TrashState> {
@override
Future<void> close() async {
await listener.stop();
await listener.close();
return super.close();
}
}

View File

@ -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<ViewEvent, ViewState> {
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<ViewEvent>((event, emit) async {
await event.map(
initial: (e) {
@ -36,7 +37,7 @@ class ViewBloc extends Bloc<ViewEvent, ViewState> {
);
},
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<ViewEvent, ViewState> {
);
},
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<ViewEvent, ViewState> {
);
},
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<ViewEvent, ViewState> {
@override
Future<void> close() async {
await listener.stop();
await listener.close();
return super.close();
}
}

View File

@ -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<WelcomeEvent, WelcomeState> {
final UserRepo repo;
final IUserListener listener;
final UserListener listener;
WelcomeBloc({required this.repo, required this.listener}) : super(WelcomeState.initial()) {
on<WelcomeEvent>(
(event, emit) async {

View File

@ -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<Either<DocumentDelta, FlowyError>> readDoc();
Future<Either<DocumentDelta, FlowyError>> composeDelta({required String json});
Future<Either<Unit, FlowyError>> closeDoc();
}

View File

@ -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<Either<ExportData, FlowyError>> exportText(String docId);
Future<Either<ExportData, FlowyError>> exportMarkdown(String docId);
Future<Either<ExportData, FlowyError>> exportURL(String docId);
}

View File

@ -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<Either<List<Trash>, FlowyError>> readTrash();
Future<Either<Unit, FlowyError>> putback(String trashId);
Future<Either<Unit, FlowyError>> deleteViews(List<Tuple2<String, TrashType>> trashList);
Future<Either<Unit, FlowyError>> restoreAll();
Future<Either<Unit, FlowyError>> deleteAll();
}
typedef TrashUpdatedCallback = void Function(Either<List<Trash>, FlowyError> trashOrFailed);
abstract class ITrashListener {
void start(TrashUpdatedCallback updateCallback);
Future<void> stop();
}

View File

@ -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<Either<UserProfile, FlowyError>> fetchUserProfile(String userId);
Future<Either<List<Workspace>, FlowyError>> fetchWorkspaces();
Future<Either<Unit, FlowyError>> deleteWorkspace(String workspaceId);
Future<Either<Unit, FlowyError>> signOut();
Future<Either<Unit, FlowyError>> initUser();
}
typedef UserProfileUpdatedNotifierValue = Either<UserProfile, FlowyError>;
typedef AuthNotifierValue = Either<Unit, FlowyError>;
typedef WorkspaceUpdatedNotifierValue = Either<List<Workspace>, FlowyError>;
abstract class IUserListener {
void start();
PublishNotifier<UserProfileUpdatedNotifierValue> get profileUpdatedNotifier;
PublishNotifier<AuthNotifierValue> get authDidChangedNotifier;
PublishNotifier<WorkspaceUpdatedNotifierValue> get workspaceUpdatedNotifier;
Future<void> stop();
}

View File

@ -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<View, FlowyError>);
typedef DeleteNotifierValue = Either<View, FlowyError>;
typedef UpdateNotifierValue = Either<View, FlowyError>;
typedef RestoreNotifierValue = Either<View, FlowyError>;
abstract class IView {
View get view;
Future<Either<Unit, FlowyError>> delete();
Future<Either<View, FlowyError>> rename(String newName);
Future<Either<Unit, FlowyError>> duplicate();
}
abstract class IViewListener {
void start();
PublishNotifier<UpdateNotifierValue> get updatedNotifier;
PublishNotifier<DeleteNotifierValue> get deletedNotifier;
PublishNotifier<RestoreNotifierValue> get restoredNotifier;
Future<void> stop();
}

View File

@ -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<void> resolve(GetIt getIt) async {
getIt.registerFactoryParam<UserListener, UserProfile, void>(
(user, _) => UserListener(user: user),
);
getIt.registerFactoryParam<HomeListenBloc, UserProfile, void>(
(user, _) => HomeListenBloc(getIt<UserListener>(param1: user)),
);
//
getIt.registerLazySingleton<HomeStackManager>(() => HomeStackManager());
getIt.registerFactoryParam<WelcomeBloc, UserProfile, void>(
(user, _) => WelcomeBloc(
repo: UserRepo(user: user),
listener: getIt<IUserListener>(param1: user),
listener: getIt<UserListener>(param1: user),
),
);
@ -43,22 +44,16 @@ class HomeDepsResolver {
(user, workspaceId) => WorkspaceListener(repo: WorkspaceListenerRepo(user: user, workspaceId: workspaceId)));
// View
getIt.registerFactoryParam<IView, View, void>((view, _) => IViewImpl(repo: ViewRepository(view: view)));
getIt.registerFactoryParam<IViewListener, View, void>(
(view, _) => IViewListenerImpl(repo: ViewListenerRepository(view: view)));
getIt.registerFactoryParam<ViewBloc, View, void>(
(view, _) => ViewBloc(
viewManager: getIt<IView>(param1: view),
listener: getIt<IViewListener>(param1: view),
),
getIt.registerFactoryParam<ViewListener, View, void>(
(view, _) => ViewListener(view: view),
);
// Doc
getIt.registerFactoryParam<IDoc, String, void>((docId, _) => IDocImpl(repo: DocRepository(docId: docId)));
// User
getIt.registerFactoryParam<IUser, UserProfile, void>((user, _) => IUserImpl(repo: UserRepo(user: user)));
getIt.registerFactoryParam<IUserListener, UserProfile, void>((user, _) => IUserListenerImpl(user: user));
getIt.registerFactoryParam<ViewBloc, View, void>(
(view, _) => ViewBloc(
repo: ViewRepository(view: view),
listener: getIt<ViewListener>(param1: view),
),
);
//Menu Bloc
getIt.registerFactoryParam<MenuBloc, UserProfile, String>(
@ -69,14 +64,18 @@ class HomeDepsResolver {
);
getIt.registerFactoryParam<MenuUserBloc, UserProfile, void>(
(user, _) => MenuUserBloc(getIt<IUser>(param1: user), getIt<IUserListener>(param1: user)));
(user, _) => MenuUserBloc(
UserRepo(user: user),
getIt<UserListener>(param1: user),
),
);
// App
getIt.registerFactoryParam<AppBloc, App, void>(
(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<DocBloc, View, void>(
(view, _) => DocBloc(
view: view,
docManager: getIt<IDoc>(param1: view.id),
listener: getIt<IViewListener>(param1: view),
trasnManager: getIt<ITrash>(),
repo: DocRepository(docId: view.id),
listener: getIt<ViewListener>(param1: view),
trashRepo: getIt<TrashRepo>(),
),
);
// trash
getIt.registerLazySingleton<TrashRepo>(() => TrashRepo());
getIt.registerLazySingleton<TrashListenerRepo>(() => TrashListenerRepo());
getIt.registerFactory<ITrash>(() => ITrashImpl(repo: getIt<TrashRepo>()));
getIt.registerFactory<ITrashListener>(() => ITrashListenerImpl(repo: getIt<TrashListenerRepo>()));
getIt.registerFactory<TrashBloc>(() => TrashBloc(trasnManager: getIt<ITrash>(), listener: getIt<ITrashListener>()));
getIt.registerLazySingleton<TrashListener>(() => TrashListener());
getIt.registerFactory<TrashBloc>(
() => TrashBloc(
repo: getIt<TrashRepo>(),
listener: getIt<TrashListener>(),
),
);
// share
getIt.registerLazySingleton<ShareRepo>(() => ShareRepo());
getIt.registerFactory<IShare>(() => IShareImpl(repo: getIt<ShareRepo>()));
getIt.registerFactoryParam<DocShareBloc, View, void>(
(view, _) => DocShareBloc(view: view, shareManager: getIt<IShare>()));
(view, _) => DocShareBloc(view: view, repo: getIt<ShareRepo>()));
}
}

View File

@ -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<Either<Unit, FlowyError>> closeDoc() {
return repo.closeDoc();
}
@override
Future<Either<DocumentDelta, FlowyError>> readDoc() async {
final docOrFail = await repo.readDoc();
return docOrFail;
}
@override
Future<Either<DocumentDelta, FlowyError>> 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);
}

View File

@ -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<Either<ExportData, FlowyError>> exportText(String docId) {
return repo.export(docId, ExportType.Text);
}
@override
Future<Either<ExportData, FlowyError>> exportMarkdown(String docId) {
return repo.export(docId, ExportType.Markdown);
}
@override
Future<Either<ExportData, FlowyError>> exportURL(String docId) {
return repo.export(docId, ExportType.Link);
}
}

View File

@ -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<Either<List<Trash>, FlowyError>> readTrash() {
return repo.readTrash().then((result) {
return result.fold(
(repeatedTrash) => left(repeatedTrash.items),
(err) => right(err),
);
});
}
@override
Future<Either<Unit, FlowyError>> putback(String trashId) {
return repo.putback(trashId);
}
@override
Future<Either<Unit, FlowyError>> deleteAll() {
return repo.deleteAll();
}
@override
Future<Either<Unit, FlowyError>> restoreAll() {
return repo.restoreAll();
}
@override
Future<Either<Unit, FlowyError>> deleteViews(List<Tuple2<String, TrashType>> trashList) {
return repo.deleteViews(trashList);
}
}
class ITrashListenerImpl extends ITrashListener {
TrashListenerRepo repo;
ITrashListenerImpl({
required this.repo,
});
@override
Future<void> stop() async {
await repo.close();
}
@override
void start(TrashUpdatedCallback updateCallback) {
repo.startListening(trashUpdated: updateCallback);
}
}

View File

@ -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<Either<Unit, FlowyError>> deleteWorkspace(String workspaceId) {
return repo.deleteWorkspace(workspaceId: workspaceId);
}
@override
Future<Either<UserProfile, FlowyError>> fetchUserProfile(String userId) {
return repo.fetchUserProfile(userId: userId);
}
@override
Future<Either<Unit, FlowyError>> signOut() {
return repo.signOut();
}
@override
UserProfile get user => repo.user;
@override
Future<Either<List<Workspace>, FlowyError>> fetchWorkspaces() {
return repo.getWorkspaces();
}
@override
Future<Either<Unit, FlowyError>> initUser() {
return repo.initUser();
}
}
class IUserListenerImpl extends IUserListener {
StreamSubscription<SubscribeObject>? _subscription;
@override
final profileUpdatedNotifier = PublishNotifier<UserProfileUpdatedNotifierValue>();
@override
final authDidChangedNotifier = PublishNotifier<AuthNotifierValue>();
@override
final workspaceUpdatedNotifier = PublishNotifier<WorkspaceUpdatedNotifierValue>();
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<void> stop() async {
await _subscription?.cancel();
profileUpdatedNotifier.dispose();
authDidChangedNotifier.dispose();
workspaceUpdatedNotifier.dispose();
}
void _notificationCallback(FolderNotification ty, Either<Uint8List, FlowyError> 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<Uint8List, FlowyError> result) {
switch (ty) {
case user.UserNotification.UserUnauthorized:
result.fold(
(payload) => profileUpdatedNotifier.value = left(UserProfile.fromBuffer(payload)),
(error) => profileUpdatedNotifier.value = right(error),
);
break;
default:
break;
}
}
}

View File

@ -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<Either<Unit, FlowyError>> delete() {
return repo.delete().then((result) {
return result.fold(
(_) => left(unit),
(error) => right(error),
);
});
}
@override
Future<Either<View, FlowyError>> rename(String newName) {
return repo.updateView(name: newName);
}
@override
Future<Either<Unit, FlowyError>> duplicate() {
return repo.duplicate();
}
}
class IViewListenerImpl extends IViewListener {
final ViewListenerRepository repo;
IViewListenerImpl({
required this.repo,
});
@override
void start() {
repo.start();
}
@override
Future<void> stop() async {
await repo.close();
}
@override
PublishNotifier<DeleteNotifierValue> get deletedNotifier => repo.deletedNotifier;
@override
PublishNotifier<UpdateNotifierValue> get updatedNotifier => repo.updatedNotifier;
@override
PublishNotifier<RestoreNotifierValue> get restoredNotifier => repo.restoredNotifier;
}

View File

@ -66,14 +66,14 @@ class AppRepository {
typedef AppDidUpdateCallback = void Function(App app);
typedef ViewsDidChangeCallback = void Function(Either<List<View>, FlowyError> viewsOrFailed);
class AppListenerRepository {
class AppListener {
StreamSubscription<SubscribeObject>? _subscription;
ViewsDidChangeCallback? _viewsChanged;
AppDidUpdateCallback? _updated;
late FolderNotificationParser _parser;
String appId;
AppListenerRepository({
AppListener({
required this.appId,
});

View File

@ -12,4 +12,16 @@ class ShareRepo {
return FolderEventExportDocument(request).send();
}
Future<Either<ExportData, FlowyError>> exportText(String docId) {
return export(docId, ExportType.Text);
}
Future<Either<ExportData, FlowyError>> exportMarkdown(String docId) {
return export(docId, ExportType.Markdown);
}
Future<Either<ExportData, FlowyError>> exportURL(String docId) {
return export(docId, ExportType.Link);
}
}

View File

@ -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<List<Trash>, FlowyError> trashOrFailed);
class TrashListener {
StreamSubscription<SubscribeObject>? _subscription;
TrashUpdatedCallback? _trashUpdated;
late FolderNotificationParser _parser;

View File

@ -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<UserProfile, FlowyError>;
typedef AuthNotifierValue = Either<Unit, FlowyError>;
typedef WorkspaceUpdatedNotifierValue = Either<List<Workspace>, FlowyError>;
class UserListener {
StreamSubscription<SubscribeObject>? _subscription;
final profileUpdatedNotifier = PublishNotifier<UserProfileUpdatedNotifierValue>();
final authDidChangedNotifier = PublishNotifier<AuthNotifierValue>();
final workspaceUpdatedNotifier = PublishNotifier<WorkspaceUpdatedNotifierValue>();
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<void> stop() async {
await _subscription?.cancel();
profileUpdatedNotifier.dispose();
authDidChangedNotifier.dispose();
workspaceUpdatedNotifier.dispose();
}
void _notificationCallback(FolderNotification ty, Either<Uint8List, FlowyError> 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<Uint8List, FlowyError> result) {
switch (ty) {
case user.UserNotification.UserUnauthorized:
result.fold(
(payload) => profileUpdatedNotifier.value = left(UserProfile.fromBuffer(payload)),
(error) => profileUpdatedNotifier.value = right(error),
);
break;
default:
break;
}
}
}

View File

@ -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<View, FlowyError>;
typedef UpdateNotifierValue = Either<View, FlowyError>;
typedef RestoreNotifierValue = Either<View, FlowyError>;
class ViewListener {
StreamSubscription<SubscribeObject>? _subscription;
PublishNotifier<UpdateNotifierValue> updatedNotifier = PublishNotifier<UpdateNotifierValue>();
PublishNotifier<DeleteNotifierValue> deletedNotifier = PublishNotifier<DeleteNotifierValue>();
@ -57,7 +59,7 @@ class ViewListenerRepository {
late FolderNotificationParser _parser;
View view;
ViewListenerRepository({
ViewListener({
required this.view,
});

View File

@ -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<int, ShareActionWrapper> {
View _view;
late IViewListener _listener;
late ViewListener _listener;
final ValueNotifier<int> _isUpdated = ValueNotifier<int>(0);
DocStackContext({required View view, Key? key}) : _view = view {
_listener = getIt<IViewListener>(param1: view);
_listener = getIt<ViewListener>(param1: view);
_listener.updatedNotifier.addPublishListener((result) {
result.fold(
(newView) {
@ -78,7 +77,7 @@ class DocStackContext extends HomeStackContext<int, ShareActionWrapper> {
@override
void dispose() {
_listener.stop();
_listener.close();
}
}