i_user_impl.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:dartz/dartz.dart';
  2. import 'package:app_flowy/workspace/domain/i_user.dart';
  3. import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
  4. import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
  5. export 'package:app_flowy/workspace/domain/i_user.dart';
  6. export 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
  7. class IUserImpl extends IUser {
  8. UserRepo repo;
  9. IUserImpl({
  10. required this.repo,
  11. });
  12. @override
  13. Future<Either<Unit, WorkspaceError>> deleteWorkspace(String workspaceId) {
  14. return repo.deleteWorkspace(workspaceId: workspaceId);
  15. }
  16. @override
  17. Future<Either<UserProfile, UserError>> fetchUserProfile(String userId) {
  18. return repo.fetchUserProfile(userId: userId);
  19. }
  20. @override
  21. Future<Either<Unit, UserError>> signOut() {
  22. return repo.signOut();
  23. }
  24. @override
  25. UserProfile get user => repo.user;
  26. @override
  27. Future<Either<List<Workspace>, WorkspaceError>> fetchWorkspaces() {
  28. return repo.getWorkspaces();
  29. }
  30. }
  31. class IUserWorkspaceListWatchImpl extends IUserWorkspaceListWatch {
  32. UserWatchRepo repo;
  33. IUserWorkspaceListWatchImpl({
  34. required this.repo,
  35. });
  36. @override
  37. void startWatching({
  38. WorkspaceListUpdatedCallback? workspaceListUpdatedCallback,
  39. }) {
  40. repo.startWatching(workspaceListUpdated: workspaceListUpdatedCallback);
  41. }
  42. @override
  43. Future<void> stopWatching() async {
  44. await repo.close();
  45. }
  46. }