Skip to content

Commit

Permalink
wip rank popular/custom, too
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Dec 7, 2024
1 parent 7291b38 commit 5a88224
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions lib/model/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,35 @@ class EmojiAutocompleteView extends AutocompleteView<EmojiAutocompleteQuery, Emo
return match == null ? null : EmojiAutocompleteResult(match, candidate);
}

static const _numResultRanks = 3;
static const _numResultRanks = 6;

static int _rankResult(EmojiAutocompleteResult result) {
// TODO(#1068): rank emoji results also by popular, realm, other
if (result.matchQuality == EmojiMatchQuality.exact) {
return 0;
}
final candidate = result.candidate;
if (_isPopularEmoji(candidate)) {
return 1;
}
final isRealmEmoji = (candidate.emojiType == ReactionType.realmEmoji);
return switch (result.matchQuality) {
EmojiMatchQuality.exact => 0,
EmojiMatchQuality.prefix => 1,
EmojiMatchQuality.internal => 2,
EmojiMatchQuality.exact => throw Error(), // handled above
EmojiMatchQuality.prefix => isRealmEmoji ? 2 : 3,
// TODO word-boundary vs. not
EmojiMatchQuality.internal => isRealmEmoji ? 4 : 5,
};
}

static bool _isPopularEmoji(EmojiCandidate candidate) {
return candidate.emojiType == ReactionType.unicodeEmoji
&& _popularEmojiSet.contains(candidate.emojiCode);
}

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

class EmojiAutocompleteQuery extends ComposeAutocompleteQuery {
Expand Down

0 comments on commit 5a88224

Please sign in to comment.