@@ -31,6 +31,7 @@ import 'recent_senders.dart';
31
31
import 'channel.dart' ;
32
32
import 'typing_status.dart' ;
33
33
import 'unreads.dart' ;
34
+ import 'user.dart' ;
34
35
35
36
export 'package:drift/drift.dart' show Value;
36
37
export 'database.dart' show Account, AccountsCompanion, AccountAlreadyExistsException;
@@ -266,7 +267,7 @@ class AccountNotFoundException implements Exception {}
266
267
/// This class does not attempt to poll an event queue
267
268
/// to keep the data up to date. For that behavior, see
268
269
/// [UpdateMachine] .
269
- class PerAccountStore extends ChangeNotifier with EmojiStore , ChannelStore , MessageStore {
270
+ class PerAccountStore extends ChangeNotifier with EmojiStore , UserStore , ChannelStore , MessageStore {
270
271
/// Construct a store for the user's data, starting from the given snapshot.
271
272
///
272
273
/// The global store must already have been updated with
@@ -316,11 +317,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
316
317
typingStartedWaitPeriod: Duration (
317
318
milliseconds: initialSnapshot.serverTypingStartedWaitPeriodMilliseconds),
318
319
),
319
- users: Map .fromEntries (
320
- initialSnapshot.realmUsers
321
- .followedBy (initialSnapshot.realmNonActiveUsers)
322
- .followedBy (initialSnapshot.crossRealmBots)
323
- .map ((user) => MapEntry (user.userId, user))),
320
+ users: UserStoreImpl (initialSnapshot: initialSnapshot),
324
321
typingStatus: TypingStatus (
325
322
selfUserId: account.userId,
326
323
typingStartedExpiryPeriod: Duration (milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
@@ -354,7 +351,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
354
351
required this .selfUserId,
355
352
required this .userSettings,
356
353
required this .typingNotifier,
357
- required this . users,
354
+ required UserStoreImpl users,
358
355
required this .typingStatus,
359
356
required ChannelStoreImpl channels,
360
357
required MessageStoreImpl messages,
@@ -367,6 +364,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
367
364
assert (emoji.realmUrl == realmUrl),
368
365
_globalStore = globalStore,
369
366
_emoji = emoji,
367
+ _users = users,
370
368
_channels = channels,
371
369
_messages = messages;
372
370
@@ -465,7 +463,10 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
465
463
////////////////////////////////
466
464
// Users and data about them.
467
465
468
- final Map <int , User > users;
466
+ @override
467
+ Map <int , User > get users => _users.users;
468
+
469
+ final UserStoreImpl _users;
469
470
470
471
final TypingStatus typingStatus;
471
472
@@ -634,44 +635,18 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
634
635
635
636
case RealmUserAddEvent ():
636
637
assert (debugLog ("server event: realm_user/add" ));
637
- users[event.person.userId] = event.person ;
638
+ _users. handleRealmUserEvent ( event) ;
638
639
notifyListeners ();
639
640
640
641
case RealmUserRemoveEvent ():
641
642
assert (debugLog ("server event: realm_user/remove" ));
642
- users. remove (event.userId );
643
+ _users. handleRealmUserEvent (event);
643
644
autocompleteViewManager.handleRealmUserRemoveEvent (event);
644
645
notifyListeners ();
645
646
646
647
case RealmUserUpdateEvent ():
647
648
assert (debugLog ("server event: realm_user/update" ));
648
- final user = users[event.userId];
649
- if (user == null ) {
650
- return ; // TODO log
651
- }
652
- if (event.fullName != null ) user.fullName = event.fullName! ;
653
- if (event.avatarUrl != null ) user.avatarUrl = event.avatarUrl! ;
654
- if (event.avatarVersion != null ) user.avatarVersion = event.avatarVersion! ;
655
- if (event.timezone != null ) user.timezone = event.timezone! ;
656
- if (event.botOwnerId != null ) user.botOwnerId = event.botOwnerId! ;
657
- if (event.role != null ) user.role = event.role! ;
658
- if (event.isBillingAdmin != null ) user.isBillingAdmin = event.isBillingAdmin! ;
659
- if (event.deliveryEmail != null ) user.deliveryEmail = event.deliveryEmail! .value;
660
- if (event.newEmail != null ) user.email = event.newEmail! ;
661
- if (event.isActive != null ) user.isActive = event.isActive! ;
662
- if (event.customProfileField != null ) {
663
- final profileData = (user.profileData ?? = {});
664
- final update = event.customProfileField! ;
665
- if (update.value != null ) {
666
- profileData[update.id] = ProfileFieldUserData (value: update.value! , renderedValue: update.renderedValue);
667
- } else {
668
- profileData.remove (update.id);
669
- }
670
- if (profileData.isEmpty) {
671
- // null is equivalent to `{}` for efficiency; see [User._readProfileData].
672
- user.profileData = null ;
673
- }
674
- }
649
+ _users.handleRealmUserEvent (event);
675
650
autocompleteViewManager.handleRealmUserUpdateEvent (event);
676
651
notifyListeners ();
677
652
0 commit comments