Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
config view repository
appflowy3bb12d50bdc2
diff --git a/app_flowy/lib/workspace/domain/i_view.dart b/app_flowy/lib/workspace/domain/i_view.dartindex 27b4903687..4feabb77f4 100644--- a/app_flowy/lib/workspace/domain/i_view.dart+++ b/app_flowy/lib/workspace/domain/i_view.dart@@ -1,3 +1,7 @@+import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';++typedef ViewUpdatedCallback = void Function(View view);+abstract class IViewWatch {void startWatching({ViewUpdatedCallback? updatedCallback});diff --git a/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/view_repo.dartindex 461145174d..d1b1a95ce8 100644--- a/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart+++ b/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart@@ -1,23 +1,46 @@-import 'package:app_flowy/workspace/domain/i_view.dart';-import 'package:flowy_sdk/protobuf/flowy-observable/subject.pb.dart';-import 'package:dartz/dartz.dart';import 'dart:async';+import 'package:dartz/dartz.dart';+import 'package:flowy_infra/flowy_logger.dart';+import 'package:flowy_sdk/dispatch/dispatch.dart';+import 'package:flowy_sdk/protobuf/flowy-observable/subject.pb.dart';+import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';+import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart';+import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';+import 'package:flowy_sdk/protobuf/flowy-workspace/view_query.pb.dart';+import 'package:flowy_sdk/rust_stream.dart';++import 'package:app_flowy/workspace/domain/i_view.dart';++class ViewRepository {+ String viewId;+ ViewRepository({+ required this.viewId,+ });++ Future<Either<View, WorkspaceError>> getView() {+ final request = QueryViewRequest.create()..viewId = viewId;+ return WorkspaceEventReadView(request).send();+ }+}+class ViewWatchRepository {StreamSubscription<ObservableSubject>? _subscription;ViewUpdatedCallback? _updatedCallback;String viewId;+ late ViewRepository _repo;ViewWatchRepository({required this.viewId,- });+ }) {+ _repo = ViewRepository(viewId: viewId);+ }void startWatching({ViewUpdatedCallback? updatedCallback,}) {- _addViewCallback = addViewCallback;_updatedCallback = updatedCallback;_subscription = RustStreamReceiver.listen((observable) {- if (observable.subjectId != appId) {+ if (observable.subjectId != viewId) {return;}@@ -27,4 +50,26 @@ class ViewWatchRepository {}});}++ void _handleObservableType(WorkspaceObservable ty) {+ switch (ty) {+ case WorkspaceObservable.ViewUpdateDesc:+ if (_updatedCallback == null) {+ return;+ }+ _repo.getView().then((result) {+ result.fold(+ (view) => _updatedCallback!(view),+ (error) => Log.error(error),+ );+ });+ break;+ default:+ break;+ }+ }++ Future<void> close() async {+ await _subscription?.cancel();+ }}diff --git a/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart b/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dartindex 12a62522d6..398599fdff 100644--- a/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart+++ b/app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart@@ -152,6 +152,40 @@ class WorkspaceEventCreateView {}}+class WorkspaceEventReadView {+ QueryViewRequest request;+ WorkspaceEventReadView(this.request);++ Future<Either<View, WorkspaceError>> send() {+ final request = FFIRequest.create()+ ..event = WorkspaceEvent.ReadView.toString()+ ..payload = requestToBytes(this.request);++ return Dispatch.asyncRequest(request)+ .then((bytesResult) => bytesResult.fold(+ (okBytes) => left(View.fromBuffer(okBytes)),+ (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),+ ));+ }+}++class WorkspaceEventUpdateView {+ UpdateViewRequest request;+ WorkspaceEventUpdateView(this.request);++ Future<Either<Unit, WorkspaceError>> send() {+ final request = FFIRequest.create()+ ..event = WorkspaceEvent.UpdateView.toString()+ ..payload = requestToBytes(this.request);++ return Dispatch.asyncRequest(request)+ .then((bytesResult) => bytesResult.fold(+ (bytes) => left(unit),+ (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),+ ));+ }+}+class UserEventGetStatus {UserEventGetStatus();diff --git a/rust-lib/flowy-workspace/src/event.rs b/rust-lib/flowy-workspace/src/event.rsindex f3658240f1..d4bfe12cb1 100644--- a/rust-lib/flowy-workspace/src/event.rs+++ b/rust-lib/flowy-workspace/src/event.rs@@ -33,6 +33,6 @@ pub enum WorkspaceEvent {ReadView = 202,#[display(fmt = "UpdateView")]- #[event(input = "UpdateViewRequest", output = "View")]+ #[event(input = "UpdateViewRequest")]UpdateView = 203,}diff --git a/rust-lib/flowy-workspace/src/module.rs b/rust-lib/flowy-workspace/src/module.rsindex 6f5b4b14d6..d6df59bad3 100644--- a/rust-lib/flowy-workspace/src/module.rs+++ b/rust-lib/flowy-workspace/src/module.rs@@ -47,4 +47,6 @@ pub fn create(user: Arc<dyn WorkspaceUser>, database: Arc<dyn WorkspaceDatabase>.event(WorkspaceEvent::CreateApp, create_app).event(WorkspaceEvent::GetApp, get_app).event(WorkspaceEvent::CreateView, create_view)+ .event(WorkspaceEvent::ReadView, read_view)+ .event(WorkspaceEvent::UpdateView, update_view)}