|  | @@ -12,26 +12,55 @@ import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart';
 | 
	
		
			
				|  |  |  import 'package:flowy_sdk/protobuf/flowy-user/dart_notification.pb.dart' as user;
 | 
	
		
			
				|  |  |  import 'package:flowy_sdk/rust_stream.dart';
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -typedef UserProfileUpdatedNotifierValue = Either<UserProfile, FlowyError>;
 | 
	
		
			
				|  |  | -typedef AuthNotifierValue = Either<Unit, FlowyError>;
 | 
	
		
			
				|  |  | -typedef WorkspaceUpdatedNotifierValue = Either<List<Workspace>, FlowyError>;
 | 
	
		
			
				|  |  | +typedef UserProfileDidUpdate = Either<UserProfile, FlowyError>;
 | 
	
		
			
				|  |  | +typedef AuthDidUpdate = Either<Unit, FlowyError>;
 | 
	
		
			
				|  |  | +typedef WorkspaceListDidUpdate = Either<List<Workspace>, FlowyError>;
 | 
	
		
			
				|  |  | +typedef WorkspaceSettingDidUpdate = Either<CurrentWorkspaceSetting, FlowyError>;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class UserListener {
 | 
	
		
			
				|  |  |    StreamSubscription<SubscribeObject>? _subscription;
 | 
	
		
			
				|  |  | -  final profileUpdatedNotifier = PublishNotifier<UserProfileUpdatedNotifierValue>();
 | 
	
		
			
				|  |  | -  final authDidChangedNotifier = PublishNotifier<AuthNotifierValue>();
 | 
	
		
			
				|  |  | -  final workspaceUpdatedNotifier = PublishNotifier<WorkspaceUpdatedNotifierValue>();
 | 
	
		
			
				|  |  | +  final _profileNotifier = PublishNotifier<UserProfileDidUpdate>();
 | 
	
		
			
				|  |  | +  final _authNotifier = PublishNotifier<AuthDidUpdate>();
 | 
	
		
			
				|  |  | +  final _workspaceListNotifier = PublishNotifier<WorkspaceListDidUpdate>();
 | 
	
		
			
				|  |  | +  final _workSettingNotifier = PublishNotifier<WorkspaceSettingDidUpdate>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    FolderNotificationParser? _workspaceParser;
 | 
	
		
			
				|  |  |    UserNotificationParser? _userParser;
 | 
	
		
			
				|  |  | -  late UserProfile _user;
 | 
	
		
			
				|  |  | +  final UserProfile _user;
 | 
	
		
			
				|  |  |    UserListener({
 | 
	
		
			
				|  |  |      required UserProfile user,
 | 
	
		
			
				|  |  | +  }) : _user = user;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  void start({
 | 
	
		
			
				|  |  | +    void Function(AuthDidUpdate)? authDidChange,
 | 
	
		
			
				|  |  | +    void Function(UserProfileDidUpdate)? profileDidUpdate,
 | 
	
		
			
				|  |  | +    void Function(WorkspaceListDidUpdate)? workspaceListDidUpdate,
 | 
	
		
			
				|  |  | +    void Function(WorkspaceSettingDidUpdate)? workspaceSettingDidUpdate,
 | 
	
		
			
				|  |  |    }) {
 | 
	
		
			
				|  |  | -    _user = user;
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +    if (authDidChange != null) {
 | 
	
		
			
				|  |  | +      _authNotifier.addListener(() {
 | 
	
		
			
				|  |  | +        authDidChange(_authNotifier.currentValue!);
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if (profileDidUpdate != null) {
 | 
	
		
			
				|  |  | +      _profileNotifier.addListener(() {
 | 
	
		
			
				|  |  | +        profileDidUpdate(_profileNotifier.currentValue!);
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if (workspaceListDidUpdate != null) {
 | 
	
		
			
				|  |  | +      _workspaceListNotifier.addListener(() {
 | 
	
		
			
				|  |  | +        workspaceListDidUpdate(_workspaceListNotifier.currentValue!);
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if (workspaceSettingDidUpdate != null) {
 | 
	
		
			
				|  |  | +      _workSettingNotifier.addListener(() {
 | 
	
		
			
				|  |  | +        workspaceSettingDidUpdate(_workSettingNotifier.currentValue!);
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  void start() {
 | 
	
		
			
				|  |  |      _workspaceParser = FolderNotificationParser(id: _user.token, callback: _notificationCallback);
 | 
	
		
			
				|  |  |      _userParser = UserNotificationParser(id: _user.token, callback: _userNotificationCallback);
 | 
	
		
			
				|  |  |      _subscription = RustStreamReceiver.listen((observable) {
 | 
	
	
		
			
				|  | @@ -44,9 +73,9 @@ class UserListener {
 | 
	
		
			
				|  |  |      _workspaceParser = null;
 | 
	
		
			
				|  |  |      _userParser = null;
 | 
	
		
			
				|  |  |      await _subscription?.cancel();
 | 
	
		
			
				|  |  | -    profileUpdatedNotifier.dispose();
 | 
	
		
			
				|  |  | -    authDidChangedNotifier.dispose();
 | 
	
		
			
				|  |  | -    workspaceUpdatedNotifier.dispose();
 | 
	
		
			
				|  |  | +    _profileNotifier.dispose();
 | 
	
		
			
				|  |  | +    _authNotifier.dispose();
 | 
	
		
			
				|  |  | +    _workspaceListNotifier.dispose();
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    void _notificationCallback(FolderNotification ty, Either<Uint8List, FlowyError> result) {
 | 
	
	
		
			
				|  | @@ -55,16 +84,23 @@ class UserListener {
 | 
	
		
			
				|  |  |        case FolderNotification.UserDeleteWorkspace:
 | 
	
		
			
				|  |  |        case FolderNotification.WorkspaceListUpdated:
 | 
	
		
			
				|  |  |          result.fold(
 | 
	
		
			
				|  |  | -          (payload) => workspaceUpdatedNotifier.value = left(RepeatedWorkspace.fromBuffer(payload).items),
 | 
	
		
			
				|  |  | -          (error) => workspaceUpdatedNotifier.value = right(error),
 | 
	
		
			
				|  |  | +          (payload) => _workspaceListNotifier.value = left(RepeatedWorkspace.fromBuffer(payload).items),
 | 
	
		
			
				|  |  | +          (error) => _workspaceListNotifier.value = right(error),
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +        break;
 | 
	
		
			
				|  |  | +      case FolderNotification.WorkspaceSetting:
 | 
	
		
			
				|  |  | +        result.fold(
 | 
	
		
			
				|  |  | +          (payload) => _workSettingNotifier.value = left(CurrentWorkspaceSetting.fromBuffer(payload)),
 | 
	
		
			
				|  |  | +          (error) => _workSettingNotifier.value = right(error),
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |          break;
 | 
	
		
			
				|  |  |        case FolderNotification.UserUnauthorized:
 | 
	
		
			
				|  |  |          result.fold(
 | 
	
		
			
				|  |  |            (_) {},
 | 
	
		
			
				|  |  | -          (error) => authDidChangedNotifier.value = right(FlowyError.create()..code = ErrorCode.UserUnauthorized.value),
 | 
	
		
			
				|  |  | +          (error) => _authNotifier.value = right(FlowyError.create()..code = ErrorCode.UserUnauthorized.value),
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |          break;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |        default:
 | 
	
		
			
				|  |  |          break;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -74,8 +110,8 @@ class UserListener {
 | 
	
		
			
				|  |  |      switch (ty) {
 | 
	
		
			
				|  |  |        case user.UserNotification.UserUnauthorized:
 | 
	
		
			
				|  |  |          result.fold(
 | 
	
		
			
				|  |  | -          (payload) => profileUpdatedNotifier.value = left(UserProfile.fromBuffer(payload)),
 | 
	
		
			
				|  |  | -          (error) => profileUpdatedNotifier.value = right(error),
 | 
	
		
			
				|  |  | +          (payload) => _profileNotifier.value = left(UserProfile.fromBuffer(payload)),
 | 
	
		
			
				|  |  | +          (error) => _profileNotifier.value = right(error),
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |          break;
 | 
	
		
			
				|  |  |        default:
 |