[backend/core] Canonicalize 'heavy black heart' reactions to 'red heart emoji'

Misskey incorrectly sends these without the emoji version selector, so we have to canonicalize them.
This commit is contained in:
Laura Hausmann 2024-08-17 01:07:52 +02:00
parent 05f6546f48
commit 19b6b50db5
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 9 additions and 2 deletions

View file

@ -142,8 +142,14 @@ public partial class EmojiService(
return resolved;
}
// This is technically the unicode character 'heavy black heart', but misskey doesn't send the emoji version selector, so here we are.
private const string MisskeyHeart = "\u2764";
private const string EmojiVersionSelector = "\ufe0f";
public async Task<string> ResolveEmojiName(string name, string? host)
{
if (name == MisskeyHeart)
return name + EmojiVersionSelector;
if (EmojiHelpers.IsEmoji(name))
return name;

View file

@ -7,7 +7,7 @@ public class EmojiTests
{
private static void TestEmojiRegexTemplate(string input, bool expectedOutput) =>
EmojiHelpers.IsEmoji(input).Should().Be(expectedOutput);
[TestMethod]
[DataRow("\ud83d\ude84")] // high speed train (E1.0/U6.0)
[DataRow("\ud83c\udfc2\ud83c\udffd")] // snowboarder: medium skin tone (E2.0)
@ -31,8 +31,9 @@ public class EmojiTests
public void TestEmojiRegexPlainText(string input) => TestEmojiRegexTemplate(input, false);
[TestMethod]
[DataRow("\u2122", "\ufe0f")] // trademark sign
[DataRow("\u2122", "\ufe0f")] // trademark sign
[DataRow("\ud83d\udd74", "\ufe0f")] // man in business suit levitating
[DataRow("\u2764", "\ufe0f")] // heavy black heart / red heart
public void TestEmojiRegexEmojiSelector(string input, string selector)
{
TestEmojiRegexTemplate(input, false);