Skip to content

Commit 2fae1de

Browse files
chrisbobbegnprice
authored andcommitted
emoji [nfc]: Move list of popular emoji codes to its own static field
For #1495, we'll want to keep the hard-coded list of emoji codes but get the names from ServerEmojiData. This refactor prepares for that by separating where we source the codes and the names.
1 parent b12e97b commit 2fae1de

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

lib/model/emoji.dart

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,33 +221,45 @@ class EmojiStoreImpl extends PerAccountStoreBase with EmojiStore {
221221
static final _popularCandidates = _generatePopularCandidates();
222222

223223
static List<EmojiCandidate> _generatePopularCandidates() {
224-
EmojiCandidate candidate(String emojiCode, String emojiUnicode,
225-
List<String> names) {
224+
EmojiCandidate candidate(String emojiCode, List<String> names) {
226225
final emojiName = names.removeAt(0);
227-
assert(emojiUnicode == tryParseEmojiCodeToUnicode(emojiCode));
226+
final emojiUnicode = tryParseEmojiCodeToUnicode(emojiCode)!;
228227
return EmojiCandidate(emojiType: ReactionType.unicodeEmoji,
229228
emojiCode: emojiCode, emojiName: emojiName, aliases: names,
230229
emojiDisplay: UnicodeEmojiDisplay(
231230
emojiName: emojiName, emojiUnicode: emojiUnicode));
232231
}
232+
final list = _popularEmojiCodesList;
233233
return [
234-
// This list should match web:
235-
// https://github.com/zulip/zulip/blob/83a121c7e/web/shared/src/typeahead.ts#L22-L29
236-
candidate('1f44d', '👍', ['+1', 'thumbs_up', 'like']),
237-
candidate('1f389', '🎉', ['tada']),
238-
candidate('1f642', '🙂', ['smile']),
239-
candidate( '2764', '❤', ['heart', 'love', 'love_you']),
240-
candidate('1f6e0', '🛠', ['working_on_it', 'hammer_and_wrench', 'tools']),
241-
candidate('1f419', '🐙', ['octopus']),
234+
candidate(list[0], ['+1', 'thumbs_up', 'like']),
235+
candidate(list[1], ['tada']),
236+
candidate(list[2], ['smile']),
237+
candidate(list[3], ['heart', 'love', 'love_you']),
238+
candidate(list[4], ['working_on_it', 'hammer_and_wrench', 'tools']),
239+
candidate(list[5], ['octopus']),
242240
];
243241
}
244242

245-
static final _popularEmojiCodes = (() {
246-
assert(_popularCandidates.every((c) =>
247-
c.emojiType == ReactionType.unicodeEmoji));
248-
return Set.of(_popularCandidates.map((c) => c.emojiCode));
243+
/// Codes for the popular emoji, in order; all are Unicode emoji.
244+
// This list should match web:
245+
// https://github.com/zulip/zulip/blob/83a121c7e/web/shared/src/typeahead.ts#L22-L29
246+
static final List<String> _popularEmojiCodesList = (() {
247+
String check(String emojiCode, String emojiUnicode) {
248+
assert(emojiUnicode == tryParseEmojiCodeToUnicode(emojiCode));
249+
return emojiCode;
250+
}
251+
return [
252+
check('1f44d', '👍'),
253+
check('1f389', '🎉'),
254+
check('1f642', '🙂'),
255+
check('2764', '❤'),
256+
check('1f6e0', '🛠'),
257+
check('1f419', '🐙'),
258+
];
249259
})();
250260

261+
static final Set<String> _popularEmojiCodes = Set.of(_popularEmojiCodesList);
262+
251263
static bool _isPopularEmoji(EmojiCandidate candidate) {
252264
return candidate.emojiType == ReactionType.unicodeEmoji
253265
&& _popularEmojiCodes.contains(candidate.emojiCode);

0 commit comments

Comments
 (0)