Skip to content

Commit ddc5023

Browse files
committed
emoji [nfc]: Move list of popular emoji codes to its own static field
For zulip#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 6ff20f6 commit ddc5023

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

β€Žlib/model/emoji.dart

+29-16
Original file line numberDiff line numberDiff line change
@@ -221,33 +221,46 @@ 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);
227+
assert(emojiUnicode != null);
228228
return EmojiCandidate(emojiType: ReactionType.unicodeEmoji,
229229
emojiCode: emojiCode, emojiName: emojiName, aliases: names,
230230
emojiDisplay: UnicodeEmojiDisplay(
231-
emojiName: emojiName, emojiUnicode: emojiUnicode));
231+
emojiName: emojiName, emojiUnicode: emojiUnicode!));
232232
}
233+
final list = _popularEmojiCodesList;
233234
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']),
235+
candidate(list[0], ['+1', 'thumbs_up', 'like']),
236+
candidate(list[1], ['tada']),
237+
candidate(list[2], ['smile']),
238+
candidate(list[3], ['heart', 'love', 'love_you']),
239+
candidate(list[4], ['working_on_it', 'hammer_and_wrench', 'tools']),
240+
candidate(list[5], ['octopus']),
242241
];
243242
}
244243

245-
static final _popularEmojiCodes = (() {
246-
assert(_popularCandidates.every((c) =>
247-
c.emojiType == ReactionType.unicodeEmoji));
248-
return Set.of(_popularCandidates.map((c) => c.emojiCode));
244+
/// Codes for the popular emoji, in order; all are Unicode emoji.
245+
// This list should match web:
246+
// https://github.com/zulip/zulip/blob/83a121c7e/web/shared/src/typeahead.ts#L22-L29
247+
static final List<String> _popularEmojiCodesList = (() {
248+
String check(String emojiCode, String emojiUnicode) {
249+
assert(emojiUnicode == tryParseEmojiCodeToUnicode(emojiCode));
250+
return emojiCode;
251+
}
252+
return [
253+
check('1f44d', 'πŸ‘'),
254+
check('1f389', 'πŸŽ‰'),
255+
check('1f642', 'πŸ™‚'),
256+
check('2764', '❀'),
257+
check('1f6e0', 'πŸ› '),
258+
check('1f419', 'πŸ™'),
259+
];
249260
})();
250261

262+
static final Set<String> _popularEmojiCodes = Set.of(_popularEmojiCodesList);
263+
251264
static bool _isPopularEmoji(EmojiCandidate candidate) {
252265
return candidate.emojiType == ReactionType.unicodeEmoji
253266
&& _popularEmojiCodes.contains(candidate.emojiCode);

0 commit comments

Comments
Β (0)