@@ -30,6 +30,7 @@ import 'recent_senders.dart';
30
30
import 'channel.dart' ;
31
31
import 'typing_status.dart' ;
32
32
import 'unreads.dart' ;
33
+ import 'user.dart' ;
33
34
34
35
export 'package:drift/drift.dart' show Value;
35
36
export 'database.dart' show Account, AccountsCompanion, AccountAlreadyExistsException;
@@ -237,7 +238,7 @@ class AccountNotFoundException implements Exception {}
237
238
/// This class does not attempt to poll an event queue
238
239
/// to keep the data up to date. For that behavior, see
239
240
/// [UpdateMachine] .
240
- class PerAccountStore extends ChangeNotifier with EmojiStore , ChannelStore , MessageStore {
241
+ class PerAccountStore extends ChangeNotifier with EmojiStore , UserStore , ChannelStore , MessageStore {
241
242
/// Construct a store for the user's data, starting from the given snapshot.
242
243
///
243
244
/// The global store must already have been updated with
@@ -287,11 +288,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
287
288
typingStartedWaitPeriod: Duration (
288
289
milliseconds: initialSnapshot.serverTypingStartedWaitPeriodMilliseconds),
289
290
),
290
- users: Map .fromEntries (
291
- initialSnapshot.realmUsers
292
- .followedBy (initialSnapshot.realmNonActiveUsers)
293
- .followedBy (initialSnapshot.crossRealmBots)
294
- .map ((user) => MapEntry (user.userId, user))),
291
+ users: UserStoreImpl (initialSnapshot: initialSnapshot),
295
292
typingStatus: TypingStatus (
296
293
selfUserId: account.userId,
297
294
typingStartedExpiryPeriod: Duration (milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
@@ -325,7 +322,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
325
322
required this .selfUserId,
326
323
required this .userSettings,
327
324
required this .typingNotifier,
328
- required this . users,
325
+ required UserStoreImpl users,
329
326
required this .typingStatus,
330
327
required ChannelStoreImpl channels,
331
328
required MessageStoreImpl messages,
@@ -338,6 +335,7 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
338
335
assert (emoji.realmUrl == realmUrl),
339
336
_globalStore = globalStore,
340
337
_emoji = emoji,
338
+ _users = users,
341
339
_channels = channels,
342
340
_messages = messages;
343
341
@@ -436,7 +434,10 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
436
434
////////////////////////////////
437
435
// Users and data about them.
438
436
439
- final Map <int , User > users;
437
+ @override
438
+ Map <int , User > get users => _users.users;
439
+
440
+ final UserStoreImpl _users;
440
441
441
442
final TypingStatus typingStatus;
442
443
@@ -605,44 +606,18 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, Mess
605
606
606
607
case RealmUserAddEvent ():
607
608
assert (debugLog ("server event: realm_user/add" ));
608
- users[event.person.userId] = event.person ;
609
+ _users. handleRealmUserEvent ( event) ;
609
610
notifyListeners ();
610
611
611
612
case RealmUserRemoveEvent ():
612
613
assert (debugLog ("server event: realm_user/remove" ));
613
- users. remove (event.userId );
614
+ _users. handleRealmUserEvent (event);
614
615
autocompleteViewManager.handleRealmUserRemoveEvent (event);
615
616
notifyListeners ();
616
617
617
618
case RealmUserUpdateEvent ():
618
619
assert (debugLog ("server event: realm_user/update" ));
619
- final user = users[event.userId];
620
- if (user == null ) {
621
- return ; // TODO log
622
- }
623
- if (event.fullName != null ) user.fullName = event.fullName! ;
624
- if (event.avatarUrl != null ) user.avatarUrl = event.avatarUrl! ;
625
- if (event.avatarVersion != null ) user.avatarVersion = event.avatarVersion! ;
626
- if (event.timezone != null ) user.timezone = event.timezone! ;
627
- if (event.botOwnerId != null ) user.botOwnerId = event.botOwnerId! ;
628
- if (event.role != null ) user.role = event.role! ;
629
- if (event.isBillingAdmin != null ) user.isBillingAdmin = event.isBillingAdmin! ;
630
- if (event.deliveryEmail != null ) user.deliveryEmail = event.deliveryEmail! .value;
631
- if (event.newEmail != null ) user.email = event.newEmail! ;
632
- if (event.isActive != null ) user.isActive = event.isActive! ;
633
- if (event.customProfileField != null ) {
634
- final profileData = (user.profileData ?? = {});
635
- final update = event.customProfileField! ;
636
- if (update.value != null ) {
637
- profileData[update.id] = ProfileFieldUserData (value: update.value! , renderedValue: update.renderedValue);
638
- } else {
639
- profileData.remove (update.id);
640
- }
641
- if (profileData.isEmpty) {
642
- // null is equivalent to `{}` for efficiency; see [User._readProfileData].
643
- user.profileData = null ;
644
- }
645
- }
620
+ _users.handleRealmUserEvent (event);
646
621
autocompleteViewManager.handleRealmUserUpdateEvent (event);
647
622
notifyListeners ();
648
623
0 commit comments