|  | @@ -4,6 +4,7 @@ import 'package:app_flowy/workspace/infrastructure/repos/helper.dart';
 | 
	
		
			
				|  |  |  import 'package:dartz/dartz.dart';
 | 
	
		
			
				|  |  |  import 'package:app_flowy/workspace/domain/i_user.dart';
 | 
	
		
			
				|  |  |  import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
 | 
	
		
			
				|  |  | +import 'package:flowy_infra/notifier.dart';
 | 
	
		
			
				|  |  |  import 'package:flowy_sdk/protobuf/flowy-dart-notify/protobuf.dart';
 | 
	
		
			
				|  |  |  import 'package:flowy_sdk/protobuf/flowy-user-infra/errors.pb.dart';
 | 
	
		
			
				|  |  |  // import 'package:flowy_sdk/protobuf/flowy-user/errors.pb.dart' as user_error;
 | 
	
	
		
			
				|  | @@ -53,9 +54,15 @@ class IUserImpl extends IUser {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class IUserListenerImpl extends IUserListener {
 | 
	
		
			
				|  |  |    StreamSubscription<SubscribeObject>? _subscription;
 | 
	
		
			
				|  |  | -  WorkspacesUpdatedCallback? _workspacesUpdated;
 | 
	
		
			
				|  |  | -  AuthChangedCallback? _authChanged;
 | 
	
		
			
				|  |  | -  UserProfileUpdateCallback? _profileUpdated;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  @override
 | 
	
		
			
				|  |  | +  final profileUpdatedNotifier = PublishNotifier<UserProfileUpdatedNotifierValue>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  @override
 | 
	
		
			
				|  |  | +  final authDidChangedNotifier = PublishNotifier<AuthNotifierValue>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  @override
 | 
	
		
			
				|  |  | +  final workspaceUpdatedNotifier = PublishNotifier<WorkspaceUpdatedNotifierValue>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    late WorkspaceNotificationParser _workspaceParser;
 | 
	
		
			
				|  |  |    late UserNotificationParser _userParser;
 | 
	
	
		
			
				|  | @@ -69,9 +76,7 @@ class IUserListenerImpl extends IUserListener {
 | 
	
		
			
				|  |  |    @override
 | 
	
		
			
				|  |  |    void start() {
 | 
	
		
			
				|  |  |      _workspaceParser = WorkspaceNotificationParser(id: _user.token, callback: _notificationCallback);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      _userParser = UserNotificationParser(id: _user.token, callback: _userNotificationCallback);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      _subscription = RustStreamReceiver.listen((observable) {
 | 
	
		
			
				|  |  |        _workspaceParser.parse(observable);
 | 
	
		
			
				|  |  |        _userParser.parse(observable);
 | 
	
	
		
			
				|  | @@ -83,43 +88,21 @@ class IUserListenerImpl extends IUserListener {
 | 
	
		
			
				|  |  |      await _subscription?.cancel();
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  @override
 | 
	
		
			
				|  |  | -  void setAuthCallback(AuthChangedCallback authCallback) {
 | 
	
		
			
				|  |  | -    _authChanged = authCallback;
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  @override
 | 
	
		
			
				|  |  | -  void setProfileCallback(UserProfileUpdateCallback profileCallback) {
 | 
	
		
			
				|  |  | -    _profileUpdated = profileCallback;
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  @override
 | 
	
		
			
				|  |  | -  void setWorkspacesCallback(WorkspacesUpdatedCallback workspacesCallback) {
 | 
	
		
			
				|  |  | -    _workspacesUpdated = workspacesCallback;
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |    void _notificationCallback(WorkspaceNotification ty, Either<Uint8List, WorkspaceError> result) {
 | 
	
		
			
				|  |  |      switch (ty) {
 | 
	
		
			
				|  |  |        case WorkspaceNotification.UserCreateWorkspace:
 | 
	
		
			
				|  |  |        case WorkspaceNotification.UserDeleteWorkspace:
 | 
	
		
			
				|  |  |        case WorkspaceNotification.WorkspaceListUpdated:
 | 
	
		
			
				|  |  | -        if (_workspacesUpdated != null) {
 | 
	
		
			
				|  |  | -          result.fold(
 | 
	
		
			
				|  |  | -            (payload) {
 | 
	
		
			
				|  |  | -              final workspaces = RepeatedWorkspace.fromBuffer(payload);
 | 
	
		
			
				|  |  | -              _workspacesUpdated!(left(workspaces.items));
 | 
	
		
			
				|  |  | -            },
 | 
	
		
			
				|  |  | -            (error) => _workspacesUpdated!(right(error)),
 | 
	
		
			
				|  |  | -          );
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        result.fold(
 | 
	
		
			
				|  |  | +          (payload) => workspaceUpdatedNotifier.value = left(RepeatedWorkspace.fromBuffer(payload).items),
 | 
	
		
			
				|  |  | +          (error) => workspaceUpdatedNotifier.value = right(error),
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  |          break;
 | 
	
		
			
				|  |  |        case WorkspaceNotification.UserUnauthorized:
 | 
	
		
			
				|  |  | -        if (_authChanged != null) {
 | 
	
		
			
				|  |  | -          result.fold(
 | 
	
		
			
				|  |  | -            (_) {},
 | 
	
		
			
				|  |  | -            (error) => {_authChanged!(right(UserError.create()..code = ErrorCode.UserUnauthorized.value))},
 | 
	
		
			
				|  |  | -          );
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        result.fold(
 | 
	
		
			
				|  |  | +          (_) {},
 | 
	
		
			
				|  |  | +          (error) => authDidChangedNotifier.value = right(UserError.create()..code = ErrorCode.UserUnauthorized.value),
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  |          break;
 | 
	
		
			
				|  |  |        default:
 | 
	
		
			
				|  |  |          break;
 | 
	
	
		
			
				|  | @@ -129,15 +112,10 @@ class IUserListenerImpl extends IUserListener {
 | 
	
		
			
				|  |  |    void _userNotificationCallback(user.UserNotification ty, Either<Uint8List, UserError> result) {
 | 
	
		
			
				|  |  |      switch (ty) {
 | 
	
		
			
				|  |  |        case user.UserNotification.UserUnauthorized:
 | 
	
		
			
				|  |  | -        if (_profileUpdated != null) {
 | 
	
		
			
				|  |  | -          result.fold(
 | 
	
		
			
				|  |  | -            (payload) {
 | 
	
		
			
				|  |  | -              final userProfile = UserProfile.fromBuffer(payload);
 | 
	
		
			
				|  |  | -              _profileUpdated!(left(userProfile));
 | 
	
		
			
				|  |  | -            },
 | 
	
		
			
				|  |  | -            (error) => _profileUpdated!(right(error)),
 | 
	
		
			
				|  |  | -          );
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        result.fold(
 | 
	
		
			
				|  |  | +          (payload) => profileUpdatedNotifier.value = left(UserProfile.fromBuffer(payload)),
 | 
	
		
			
				|  |  | +          (error) => profileUpdatedNotifier.value = right(error),
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  |          break;
 | 
	
		
			
				|  |  |        default:
 | 
	
		
			
				|  |  |          break;
 |