Skip to content

Commit 6c93b40

Browse files
committed
emoji: Add list of the "popular" emoji
1 parent 70004b0 commit 6c93b40

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

lib/model/emoji.dart

+38-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ mixin EmojiStore {
109109
required String emojiName,
110110
});
111111

112+
/// Zulip's list of "popular" emoji, to be given precedence in
113+
/// offering to users.
114+
///
115+
/// See description in the web code:
116+
/// https://github.com/zulip/zulip/blob/83a121c7e/web/shared/src/typeahead.ts#L3-L21
117+
// Someday this list may start varying rather than being hard-coded,
118+
// and then this will become a non-static member on EmojiStore.
119+
// For now, though, the fact it's constant is convenient when writing
120+
// tests of the logic that uses this data; so we guarantee it in the API.
121+
static Iterable<EmojiCandidate> get popularEmojiCandidates {
122+
return EmojiStoreImpl._popularCandidates;
123+
}
124+
112125
Iterable<EmojiCandidate> allEmojiCandidates();
113126

114127
// TODO cut debugServerEmojiData once we can query for lists of emoji;
@@ -207,7 +220,29 @@ class EmojiStoreImpl with EmojiStore {
207220
/// retrieving the data.
208221
Map<String, List<String>>? _serverEmojiData;
209222

210-
List<EmojiCandidate>? _allEmojiCandidates;
223+
static final _popularCandidates = _generatePopularCandidates();
224+
225+
static List<EmojiCandidate> _generatePopularCandidates() {
226+
EmojiCandidate candidate(String emojiCode, String emojiUnicode,
227+
List<String> names) {
228+
final emojiName = names.removeAt(0);
229+
assert(emojiUnicode == tryParseEmojiCodeToUnicode(emojiCode));
230+
return EmojiCandidate(emojiType: ReactionType.unicodeEmoji,
231+
emojiCode: emojiCode, emojiName: emojiName, aliases: names,
232+
emojiDisplay: UnicodeEmojiDisplay(
233+
emojiName: emojiName, emojiUnicode: emojiUnicode));
234+
}
235+
return [
236+
// This list should match web:
237+
// https://github.com/zulip/zulip/blob/83a121c7e/web/shared/src/typeahead.ts#L22-L29
238+
candidate('1f44d', '👍', ['+1', 'thumbs_up', 'like']),
239+
candidate('1f389', '🎉', ['tada']),
240+
candidate('1f642', '🙂', ['smile']),
241+
candidate( '2764', '❤', ['heart', 'love', 'love_you']),
242+
candidate('1f6e0', '🛠', ['working_on_it', 'hammer_and_wrench', 'tools']),
243+
candidate('1f419', '🐙', ['octopus']),
244+
];
245+
}
211246

212247
EmojiCandidate _emojiCandidateFor({
213248
required ReactionType emojiType,
@@ -306,6 +341,8 @@ class EmojiStoreImpl with EmojiStore {
306341
return results;
307342
}
308343

344+
List<EmojiCandidate>? _allEmojiCandidates;
345+
309346
@override
310347
Iterable<EmojiCandidate> allEmojiCandidates() {
311348
return _allEmojiCandidates ??= _generateAllCandidates();

0 commit comments

Comments
 (0)