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:
1 parent
9d3b4a40d9
commit
74cd1128bc
2 files changed
+82
-5
No files matched your search
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user