Support updated MeshCoreOne emoji reaction format

In #521, @Avi0n mentions they will be changing MeshCoreOne's reaction
format in the next release.

Here we add support for the new format, while retaining support for
the old format as "MC1Legacy".

There's some redundancy. My goal was not to maximize elegance, but
to facilitate easily tearing out support for the legacy format months
from now when we no longer care about it.

This has not been tested in the wild, as nothing is transmitting the
new format yet.
This commit is contained in:
Seth Golub committed 2026-09-07 09:56:24 -07:00
1 parent 9d3b4a40d9
commit 74cd1128bc
2 files changed
+82 -5

No files matched your search

+23 -1
View File
@@ -161,7 +161,9 @@ class ReactionHelper {
}
static ReactionInfo? parseReaction(String text) {
return parseReactionOurs(text) ?? parseReactionMC1(text);
return parseReactionOurs(text) ??
parseReactionMC1(text) ??
parseReactionMC1Legacy(text);
}
static bool _looksLikeEmoji(String emoji) {
@@ -186,6 +188,26 @@ class ReactionHelper {
}
static ReactionInfo? parseReactionMC1(String text) {
// See https://github.com/Avi0n/MeshCoreOne/blob/main/docs/Reactions.md
// This regex matches both the channel format, which includes the sender name,
// and the chat (DM) format, which omits it.
final regex = RegExp(r'^(?:@\[(.*)])?(.+?)\n([a-tv-zA-TV-Z0-9]{8})$');
final match = regex.firstMatch(text);
if (match == null) return null;
final senderName = match.group(1);
final emoji = match.group(2)!;
final hash = match.group(3)?.toLowerCase();
if (!_looksLikeEmoji(emoji)) return null;
return ReactionInfo(
targetHash: _concatenateHashAndSender(hash!, senderName),
emoji: emoji,
hashType: HashType.mc1,
);
}
static ReactionInfo? parseReactionMC1Legacy(String text) {
// See https://github.com/Avi0n/MeshCoreOne/blob/main/docs/Reactions.md
// This regex matches both the channel format, which includes the sender name,
// and the chat (DM) format, which omits it.
+59 -4
View File
@@ -373,7 +373,7 @@ void main() {
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReactionMC1(
'$emoji@[$senderName]\n$hash',
'@[$senderName]$emoji\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
@@ -381,10 +381,10 @@ void main() {
List<String> messages = [
'🥳\n01234567',
'🥳@[entropy]\n01234567',
'@[entropy]🥳\n01234567',
'\u{1f44c}\u{1f3ff}\n01234567',
'\u{1f44c}\u{1f3ff}@[entropy]\n01234567',
'🧑‍🧑‍🧒@[entropy]\n01234567', // long composite emoji - 21 bytes
'@[entropy]\u{1f44c}\u{1f3ff}\n01234567',
'@[entropy]🧑‍🧑‍🧒\n01234567', // long composite emoji - 21 bytes
'🧑‍🧑‍🧒‍🧒\n01234567', // long composite emoji - 25 bytes
];
for (String txt in messages) {
@@ -408,7 +408,62 @@ void main() {
}
});
test('parse MeshCoreOne reaction - Legacy format', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReactionMC1Legacy(
'$emoji@[$senderName]\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
List<String> messages = [
'🥳\n01234567',
'🥳@[entropy]\n01234567',
'\u{1f44c}\u{1f3ff}\n01234567',
'\u{1f44c}\u{1f3ff}@[entropy]\n01234567',
'🧑‍🧑‍🧒@[entropy]\n01234567', // long composite emoji - 21 bytes
'🧑‍🧑‍🧒‍🧒\n01234567', // long composite emoji - 25 bytes
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1Legacy(txt);
expect(info, isNotNull, reason: "$txt did not parse");
}
});
test(
'parse MeshCoreOne reaction - Legacy format - avoid false positives',
() {
List<String> messages = [
'test\nabcdefgh',
'🥳\nhashistoolong',
'🥳\nshort',
'🥳🥳\n01234567', // two emojis not composed into one grapheme
'X\n01234567',
'🥳\nabcuuxyz', // u is not valid as we don't support checksums
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1Legacy(txt);
expect(info, isNull, reason: "$txt should not have parsed");
}
},
);
test('parse MeshCoreOne reaction - main entry', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReaction(
'@[$senderName]$emoji\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
});
test('parse MeshCoreOne reaction Legacy format - main entry', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';