2021-07-23 16:45:29 +08:00
|
|
|
import 'package:dartz/dartz.dart';
|
|
|
|
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
2022-03-19 16:52:28 +08:00
|
|
|
|
2022-07-04 15:00:54 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
2021-12-14 18:04:51 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
2022-10-13 23:29:37 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-sync/document.pb.dart';
|
|
|
|
import 'package:flowy_sdk/protobuf/flowy-document/entities.pb.dart';
|
2021-07-23 16:45:29 +08:00
|
|
|
|
2022-02-28 21:02:46 -05:00
|
|
|
class DocumentService {
|
2022-10-13 23:29:37 +08:00
|
|
|
Future<Either<DocumentSnapshotPB, FlowyError>> openDocument({
|
2022-03-06 09:03:02 +08:00
|
|
|
required String docId,
|
2022-03-06 21:22:42 +08:00
|
|
|
}) async {
|
2022-07-19 14:11:29 +08:00
|
|
|
await FolderEventSetLatestView(ViewIdPB(value: docId)).send();
|
2022-03-06 21:22:42 +08:00
|
|
|
|
2022-10-13 23:29:37 +08:00
|
|
|
final payload = DocumentIdPB(value: docId);
|
|
|
|
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
|
|
|
}
|