Nathan.fooo e1c8135f5d
refactor: folder with yrs
* feat: try using folder2

* feat: update

* feat: implement handlers

* fix: compile errors

* chore: add unsafe send + sync

* feat: remove unsafe impl

* fix: replace folder with foler2

* chore: dart compile errors

* test: fix test

* test: fix test

* test: bypass existing tests

* feat: open latest view

* chore: fix dart warnings

* chore: config notification

* fix: folder notification  bugs

* fix: doesn't open the new view after creating

* chore: rename struct

* refactor: user id

* test: fix test

* chore: remove unused user_id

* fix: fix read workspace views

* chore: rename appflowy data folder

* chore: update ref

* fix: tauri build
2023-04-04 08:41:16 +08:00

100 lines
2.5 KiB
Dart

import 'dart:async';
import 'package:dartz/dartz.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/workspace.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:fixnum/fixnum.dart';
class UserBackendService {
UserBackendService({
required this.userId,
});
final Int64 userId;
static Future<Either<UserProfilePB, FlowyError>> getCurrentUserProfile() {
return UserEventGetUserProfile().send();
}
Future<Either<Unit, FlowyError>> updateUserProfile({
String? name,
String? password,
String? email,
String? iconUrl,
String? openAIKey,
}) {
var payload = UpdateUserProfilePayloadPB.create()..id = userId;
if (name != null) {
payload.name = name;
}
if (password != null) {
payload.password = password;
}
if (email != null) {
payload.email = email;
}
if (iconUrl != null) {
payload.iconUrl = iconUrl;
}
if (openAIKey != null) {
payload.openaiKey = openAIKey;
}
return UserEventUpdateUserProfile(payload).send();
}
Future<Either<Unit, FlowyError>> deleteWorkspace(
{required String workspaceId}) {
throw UnimplementedError();
}
Future<Either<Unit, FlowyError>> signOut() {
return UserEventSignOut().send();
}
Future<Either<Unit, FlowyError>> initUser() async {
return UserEventInitUser().send();
}
Future<Either<List<WorkspacePB>, FlowyError>> getWorkspaces() {
final request = WorkspaceIdPB.create();
return FolderEventReadWorkspaces(request).send().then((result) {
return result.fold(
(workspaces) => left(workspaces.items),
(error) => right(error),
);
});
}
Future<Either<WorkspacePB, FlowyError>> openWorkspace(String workspaceId) {
final request = WorkspaceIdPB.create()..value = workspaceId;
return FolderEventOpenWorkspace(request).send().then((result) {
return result.fold(
(workspace) => left(workspace),
(error) => right(error),
);
});
}
Future<Either<WorkspacePB, FlowyError>> createWorkspace(
String name, String desc) {
final request = CreateWorkspacePayloadPB.create()
..name = name
..desc = desc;
return FolderEventCreateWorkspace(request).send().then((result) {
return result.fold(
(workspace) => left(workspace),
(error) => right(error),
);
});
}
}