diff --git a/lib/helpers/pocketmesh_reaction.dart b/lib/helpers/pocketmesh_reaction.dart index fbfeaea1..da7951a1 100644 --- a/lib/helpers/pocketmesh_reaction.dart +++ b/lib/helpers/pocketmesh_reaction.dart @@ -136,9 +136,15 @@ class PocketMeshReaction { static bool _isReactionEmoji(String text) { if (text.characters.length != 1) return false; final first = text.runes.first; + // Keycaps (`1️⃣`, `#️⃣`) start with an ASCII base, so they need their own + // check. A bare digit is text; the combining keycap U+20E3 makes it emoji. + if (_isKeycapBase(first)) return text.runes.contains(0x20E3); for (final range in _emojiRanges) { if (first >= range[0] && first <= range[1]) return true; } return false; } + + static bool _isKeycapBase(int rune) => + rune == 0x23 || rune == 0x2A || (rune >= 0x30 && rune <= 0x39); } diff --git a/test/helpers/pocketmesh_reaction_test.dart b/test/helpers/pocketmesh_reaction_test.dart index 3038da7f..66c90723 100644 --- a/test/helpers/pocketmesh_reaction_test.dart +++ b/test/helpers/pocketmesh_reaction_test.dart @@ -275,6 +275,39 @@ void main() { expect(PocketMeshReaction.parse('\ndyps6yf0', isDm: true), isNull); }); + test('accepts keycap emoji, which start with a digit, # or *', () { + // One grapheme of base + U+FE0F + U+20E3. MeshCore One accepts these. + for (final keycap in [ + '#\u{FE0F}\u{20E3}', + '*\u{FE0F}\u{20E3}', + '1\u{FE0F}\u{20E3}', + '0\u{20E3}', + ]) { + expect( + PocketMeshReaction.parse('$keycap\ndyps6yf0', isDm: true)?.emoji, + keycap, + reason: 'should accept $keycap', + ); + } + expect( + PocketMeshReaction.parse( + '@[Bob]1\u{FE0F}\u{20E3}\ndyps6yf0', + isDm: false, + ), + isNotNull, + ); + }); + + test('a bare digit, # or * is not an emoji', () { + for (final plain in ['1', '#', '*']) { + expect( + PocketMeshReaction.parse('$plain\ndyps6yf0', isDm: true), + isNull, + reason: '$plain alone is text', + ); + } + }); + test('a sentence starting with an arrow is not a reaction', () { // Arrows carry the Unicode Emoji property but are ordinary punctuation. // A live capture from this mesh had U+2192 mid-sentence in a normal