Skip to content

Commit

Permalink
wip nfc switch to popularEmojiCandidates
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Dec 8, 2024
1 parent 516dee5 commit 3b9e6e5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/model/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ class EmojiStoreImpl with EmojiStore {
Map<String, List<String>>? _serverEmojiData;

static final _popularEmojiCodes = (() {
assert(zulipPopularEmojis.every((c) =>
assert(EmojiStore.popularEmojiCandidates.every((c) =>
c.emojiType == ReactionType.unicodeEmoji));
return Set.of(zulipPopularEmojis.map((c) => c.emojiCode));
return Set.of(EmojiStore.popularEmojiCandidates.map((c) => c.emojiCode));
})();

static bool _isPopularEmoji(EmojiCandidate candidate) {
Expand Down Expand Up @@ -316,7 +316,7 @@ class EmojiStoreImpl with EmojiStore {

// Include the "popular" emoji, in their canonical order
// relative to each other.
results.addAll(zulipPopularEmojis);
results.addAll(EmojiStore.popularEmojiCandidates);

final namesOverridden = {
for (final emoji in realmEmoji.values) emoji.name,
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void showMessageActionSheet({required BuildContext context, required Message mes
final showMarkAsUnreadButton = markAsUnreadSupported && isMessageRead;

final optionButtons = [
ReactionButtons(message: message, pageContext: context, popularEmojis: zulipPopularEmojis),
ReactionButtons(message: message, pageContext: context, popularEmojis: EmojiStore.popularEmojiCandidates.toList()),
StarButton(message: message, pageContext: context),
if (isComposeBoxOffered)
QuoteAndReplyButton(message: message, pageContext: context),
Expand Down
12 changes: 7 additions & 5 deletions test/model/emoji_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ void main() {
});
});

final popularCandidates = EmojiStore.popularEmojiCandidates;

Condition<Object?> isUnicodeCandidate(String? emojiCode, List<String>? names) {
return (it_) {
final it = it_.isA<EmojiCandidate>();
Expand Down Expand Up @@ -108,7 +110,7 @@ void main() {
..aliases.isEmpty();
}

List<Condition<Object?>> arePopularCandidates = zulipPopularEmojis.map(
List<Condition<Object?>> arePopularCandidates = popularCandidates.map(
(c) => isUnicodeCandidate(c.emojiCode, null)).toList();

group('allEmojiCandidates', () {
Expand Down Expand Up @@ -139,18 +141,18 @@ void main() {
// and interspersed with other emoji.
final store = prepare(unicodeEmoji: {
'1f603': ['smiley'],
for (final candidate in zulipPopularEmojis.skip(3))
for (final candidate in popularCandidates.skip(3))
candidate.emojiCode: [candidate.emojiName, ...candidate.aliases],
'1f34a': ['orange', 'tangerine', 'mandarin'],
for (final candidate in zulipPopularEmojis.take(3))
for (final candidate in popularCandidates.take(3))
candidate.emojiCode: [candidate.emojiName, ...candidate.aliases],
'1f516': ['bookmark'],
});
// In the allEmojiCandidates result, the popular emoji come first
// and are in their canonical order, even though the other Unicode emoji
// are in the same order they were given in.
check(store.allEmojiCandidates()).deepEquals([
for (final candidate in zulipPopularEmojis)
for (final candidate in popularCandidates)
isUnicodeCandidate(candidate.emojiCode,
[candidate.emojiName, ...candidate.aliases]),
isUnicodeCandidate('1f603', ['smiley']),
Expand Down Expand Up @@ -264,7 +266,7 @@ void main() {
isZulipCandidate());
}

List<Condition<Object?>> arePopularResults = zulipPopularEmojis.map(
List<Condition<Object?>> arePopularResults = popularCandidates.map(
(c) => isUnicodeResult(emojiCode: c.emojiCode)).toList();

PerAccountStore prepare({
Expand Down
8 changes: 5 additions & 3 deletions test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ void main() {

group('ReactionButtons', () {
group('popular emoji reactions;', () {
final popularCandidates = EmojiStore.popularEmojiCandidates;

testWidgets('ensure all are shown', (tester) async {
final message = eg.streamMessage();
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));
Expand All @@ -117,15 +119,15 @@ void main() {
final buttons = tester.widgetList<IconButton>(find.descendant(
of: find.byType(ReactionButtons) ,
matching: find.byType(IconButton)));
check(buttons).length.equals(zulipPopularEmojis.length);
check(buttons).length.equals(popularCandidates.length);

// Ensure all are unicode emoji buttons.
final emojis = tester.widgetList<UnicodeEmojiWidget>(find.descendant(
of: find.descendant(
of: find.byType(ReactionButtons) ,
matching: find.byType(IconButton)),
matching: find.byType(UnicodeEmojiWidget)));
check(emojis).deepEquals(zulipPopularEmojis.map<Condition<Object?>>((emoji) {
check(emojis).deepEquals(popularCandidates.map<Condition<Object?>>((emoji) {
final emojiDisplay = emoji.emojiDisplay as UnicodeEmojiDisplay;
return (it) => it.isA<UnicodeEmojiWidget>()
..emojiDisplay.which((it) => it
Expand All @@ -134,7 +136,7 @@ void main() {
}));
});

for (final emoji in zulipPopularEmojis) {
for (final emoji in popularCandidates) {
final emojiDisplay = emoji.emojiDisplay as UnicodeEmojiDisplay;

Future<void> tapButton(WidgetTester tester) async {
Expand Down

0 comments on commit 3b9e6e5

Please sign in to comment.