Skip to content

Commit 8cb3aba

Browse files
committed
emoji [nfc]: Pull out an EmojiStore and EmojiStoreImpl
This gives us a good home to add the server's list of Unicode emoji.
1 parent 6979b50 commit 8cb3aba

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

lib/model/emoji.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import '../api/model/events.dart';
2+
import '../api/model/model.dart';
3+
4+
/// The portion of [PerAccountStore] describing what emoji exist.
5+
mixin EmojiStore {
6+
Map<String, RealmEmojiItem> get realmEmoji;
7+
}
8+
9+
/// The implementation of [EmojiStore] that does the work.
10+
///
11+
/// Generally the only code that should need this class is [PerAccountStore]
12+
/// itself. Other code accesses this functionality through [PerAccountStore],
13+
/// or through the mixin [EmojiStore] which describes its interface.
14+
class EmojiStoreImpl with EmojiStore {
15+
EmojiStoreImpl({required this.realmEmoji});
16+
17+
@override
18+
Map<String, RealmEmojiItem> realmEmoji;
19+
20+
void handleRealmEmojiUpdateEvent(RealmEmojiUpdateEvent event) {
21+
realmEmoji = event.realmEmoji;
22+
}
23+
}

lib/model/store.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import '../log.dart';
2020
import '../notifications/receive.dart';
2121
import 'autocomplete.dart';
2222
import 'database.dart';
23+
import 'emoji.dart';
2324
import 'message.dart';
2425
import 'message_list.dart';
2526
import 'recent_dm_conversations.dart';
@@ -202,7 +203,7 @@ abstract class GlobalStore extends ChangeNotifier {
202203
/// This class does not attempt to poll an event queue
203204
/// to keep the data up to date. For that behavior, see
204205
/// [UpdateMachine].
205-
class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
206+
class PerAccountStore extends ChangeNotifier with EmojiStore, ChannelStore, MessageStore {
206207
/// Construct a store for the user's data, starting from the given snapshot.
207208
///
208209
/// The global store must already have been updated with
@@ -234,9 +235,9 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
234235
realmUrl: account.realmUrl,
235236
maxFileUploadSizeMib: initialSnapshot.maxFileUploadSizeMib,
236237
realmDefaultExternalAccounts: initialSnapshot.realmDefaultExternalAccounts,
237-
realmEmoji: initialSnapshot.realmEmoji,
238238
customProfileFields: _sortCustomProfileFields(initialSnapshot.customProfileFields),
239239
emailAddressVisibility: initialSnapshot.emailAddressVisibility,
240+
emoji: EmojiStoreImpl(realmEmoji: initialSnapshot.realmEmoji),
240241
accountId: accountId,
241242
selfUserId: account.userId,
242243
userSettings: initialSnapshot.userSettings,
@@ -268,9 +269,9 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
268269
required this.realmUrl,
269270
required this.maxFileUploadSizeMib,
270271
required this.realmDefaultExternalAccounts,
271-
required this.realmEmoji,
272272
required this.customProfileFields,
273273
required this.emailAddressVisibility,
274+
required EmojiStoreImpl emoji,
274275
required this.accountId,
275276
required this.selfUserId,
276277
required this.userSettings,
@@ -285,6 +286,7 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
285286
assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl),
286287
assert(realmUrl == connection.realmUrl),
287288
_globalStore = globalStore,
289+
_emoji = emoji,
288290
_channels = channels,
289291
_messages = messages;
290292

@@ -320,11 +322,18 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
320322
String get zulipVersion => account.zulipVersion;
321323
final int maxFileUploadSizeMib; // No event for this.
322324
final Map<String, RealmDefaultExternalAccount> realmDefaultExternalAccounts;
323-
Map<String, RealmEmojiItem> realmEmoji;
324325
List<CustomProfileField> customProfileFields;
325326
/// For docs, please see [InitialSnapshot.emailAddressVisibility].
326327
final EmailAddressVisibility? emailAddressVisibility; // TODO(#668): update this realm setting
327328

329+
////////////////////////////////
330+
// The realm's repertoire of available emoji.
331+
332+
@override
333+
Map<String, RealmEmojiItem> get realmEmoji => _emoji.realmEmoji;
334+
335+
EmojiStoreImpl _emoji;
336+
328337
////////////////////////////////
329338
// Data attached to the self-account on the realm.
330339

@@ -423,7 +432,7 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
423432

424433
case RealmEmojiUpdateEvent():
425434
assert(debugLog("server event: realm_emoji/update"));
426-
realmEmoji = event.realmEmoji;
435+
_emoji.handleRealmEmojiUpdateEvent(event);
427436
notifyListeners();
428437

429438
case AlertWordsEvent():

0 commit comments

Comments
 (0)