Nathan.fooo 37f269b08b
Chore/rename flowy sdk (#1679)
* chore: run flutter create on flowy_sdk

* chore: rename flowy-sdk to flowy-core

* chore: rename flowy_sdk to appflowy_backend

* chore: fix windows build

* chore: replace bloctest with test

Co-authored-by: nathan <nathan@appflowy.io>
Co-authored-by: vedon <vedon.fu@gmail.com>
2023-01-08 12:10:53 +08:00

43 lines
1.3 KiB
Dart

import 'package:dartz/dartz.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
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';
class DocumentService {
Future<Either<DocumentSnapshotPB, FlowyError>> openDocument({
required ViewPB view,
}) async {
await FolderEventSetLatestView(ViewIdPB(value: view.id)).send();
final payload = OpenDocumentContextPB()
..documentId = view.id
..documentVersion = DocumentVersionPB.V1;
// switch (view.dataFormat) {
// case ViewDataFormatPB.DeltaFormat:
// payload.documentVersion = DocumentVersionPB.V0;
// break;
// default:
// break;
// }
return DocumentEventGetDocument(payload).send();
}
Future<Either<Unit, FlowyError>> applyEdit({
required String docId,
required String operations,
}) {
final payload = EditPayloadPB.create()
..docId = docId
..operations = operations;
return DocumentEventApplyEdit(payload).send();
}
Future<Either<Unit, FlowyError>> closeDocument({required String docId}) {
final request = ViewIdPB(value: docId);
return FolderEventCloseView(request).send();
}
}