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-04-04 08:41:16 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
2023-01-08 12:10:53 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
|
|
|
import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart';
|
2023-04-13 18:53:51 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-document2/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}) {
|
2023-03-08 21:19:44 +08:00
|
|
|
final payload = ViewIdPB(value: docId);
|
|
|
|
return FolderEventCloseView(payload).send();
|
2021-07-24 09:57:17 +08:00
|
|
|
}
|
2023-04-13 18:53:51 +08:00
|
|
|
|
|
|
|
Future<Either<DocumentDataPB2, FlowyError>> openDocumentV2({
|
|
|
|
required ViewPB view,
|
|
|
|
}) async {
|
|
|
|
await FolderEventSetLatestView(ViewIdPB(value: view.id)).send();
|
|
|
|
|
|
|
|
final payload = OpenDocumentPayloadPBV2()..documentId = view.id;
|
|
|
|
|
|
|
|
return DocumentEvent2OpenDocument(payload).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Either<Unit, FlowyError>> closeDocumentV2({
|
|
|
|
required ViewPB view,
|
|
|
|
}) async {
|
|
|
|
final payload = CloseDocumentPayloadPBV2()..documentId = view.id;
|
|
|
|
return DocumentEvent2CloseDocument(payload).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Either<Unit, FlowyError>> applyAction({
|
|
|
|
required ViewPB view,
|
|
|
|
required List<BlockActionPB> actions,
|
|
|
|
}) async {
|
|
|
|
final payload = ApplyActionPayloadPBV2(
|
|
|
|
documentId: view.id,
|
|
|
|
actions: actions,
|
|
|
|
);
|
|
|
|
return DocumentEvent2ApplyAction(payload).send();
|
|
|
|
}
|
2021-07-23 16:45:29 +08:00
|
|
|
}
|