2021-07-23 16:45:29 +08:00
|
|
|
import 'package:dartz/dartz.dart';
|
2023-01-08 12:10:53 +08:00
|
|
|
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
2022-03-19 16:52:28 +08:00
|
|
|
|
2023-01-08 12:10:53 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
|
|
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
|
|
|
import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart';
|
2021-07-23 16:45:29 +08:00
|
|
|
|
2022-02-28 21:02:46 -05:00
|
|
|
class DocumentService {
|
2023-02-10 22:24:34 +08:00
|
|
|
Future<Either<DocumentDataPB, FlowyError>> openDocument({
|
2022-10-22 21:57:44 +08:00
|
|
|
required ViewPB view,
|
2022-03-06 21:22:42 +08:00
|
|
|
}) async {
|
2022-10-22 21:57:44 +08:00
|
|
|
await FolderEventSetLatestView(ViewIdPB(value: view.id)).send();
|
|
|
|
|
2023-02-10 22:24:34 +08:00
|
|
|
final payload = OpenDocumentPayloadPB()
|
2022-10-22 21:57:44 +08:00
|
|
|
..documentId = view.id
|
2023-02-10 22:24:34 +08:00
|
|
|
..version = DocumentVersionPB.V1;
|
2022-10-22 21:57:44 +08:00
|
|
|
// switch (view.dataFormat) {
|
|
|
|
// case ViewDataFormatPB.DeltaFormat:
|
|
|
|
// payload.documentVersion = DocumentVersionPB.V0;
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
2022-03-06 21:22:42 +08:00
|
|
|
|
2022-10-13 23:29:37 +08:00
|
|
|
return DocumentEventGetDocument(payload).send();
|
2021-07-24 14:05:49 +08:00
|
|
|
}
|
|
|
|
|
2022-09-13 20:23:56 +08:00
|
|
|
Future<Either<Unit, FlowyError>> applyEdit({
|
|
|
|
required String docId,
|
2022-10-20 11:35:11 +08:00
|
|
|
required String operations,
|
2022-09-13 20:23:56 +08:00
|
|
|
}) {
|
|
|
|
final payload = EditPayloadPB.create()
|
2022-10-13 23:29:37 +08:00
|
|
|
..docId = docId
|
2022-10-20 11:35:11 +08:00
|
|
|
..operations = operations;
|
2022-10-13 23:29:37 +08:00
|
|
|
return DocumentEventApplyEdit(payload).send();
|
2021-09-11 21:30:58 +08:00
|
|
|
}
|
|
|
|
|
2022-02-28 21:02:46 -05:00
|
|
|
Future<Either<Unit, FlowyError>> closeDocument({required String docId}) {
|
2022-07-19 14:11:29 +08:00
|
|
|
final request = ViewIdPB(value: docId);
|
2022-01-27 20:39:54 +08:00
|
|
|
return FolderEventCloseView(request).send();
|
2021-07-24 09:57:17 +08:00
|
|
|
}
|
2021-07-23 16:45:29 +08:00
|
|
|
}
|