Skip to content

Commit bce5084

Browse files
committed
emoji: Add list of the "popular" emoji
1 parent 3a6d127 commit bce5084

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

lib/model/emoji.dart

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ mixin EmojiStore {
113113
required String emojiName,
114114
});
115115

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

118131
// TODO cut debugServerEmojiData once we can query for lists of emoji;
@@ -200,7 +213,29 @@ class EmojiStoreImpl with EmojiStore {
200213
/// retrieving the data.
201214
Map<String, List<String>>? _serverEmojiData;
202215

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

205240
EmojiCandidate _emojiCandidateFor({
206241
required ReactionType emojiType,
@@ -264,6 +299,8 @@ class EmojiStoreImpl with EmojiStore {
264299
return results;
265300
}
266301

302+
List<EmojiCandidate>? _allEmojiCandidates;
303+
267304
@override
268305
Iterable<EmojiCandidate> allEmojiCandidates() {
269306
return _allEmojiCandidates ??= _generateAllCandidates();

0 commit comments

Comments
 (0)