Accept emoji using nameMap

This commit is contained in:
Andrew Godwin 2022-12-22 17:18:50 +00:00
parent ec3047b304
commit e066641556
2 changed files with 53 additions and 1 deletions

View File

@ -217,8 +217,16 @@ class Emoji(StatorModel):
if not create:
raise KeyError(f"No emoji with ID {data['id']}", data)
# Name could be a direct property, or in a language'd value
if "name" in data:
name = data["name"]
elif "nameMap" in data:
name = data["nameMap"]["und"]
else:
raise ValueError("No name on emoji JSON")
# create
shortcode = data["name"].lower().strip(":")
shortcode = name.lower().strip(":")
icon = data["icon"]
category = (icon.get("category") or "")[:100]
emoji = cls.objects.create(

View File

@ -0,0 +1,44 @@
import pytest
from activities.models import Emoji
@pytest.mark.django_db
def test_emoji_ingestion(identity):
"""
Tests that emoji ingest properly from JSON-LD
"""
emoji1 = Emoji.by_ap_tag(
identity.domain,
{
"icon": {
"type": "Image",
"url": "https://example.com/emoji/custom/emoji1.png",
"mediaType": "image/png",
},
"id": "https://example.com/emoji/custom/emoji1.png",
"name": ":emoji1:",
"type": "Emoji",
"updated": "1970-01-01T00:00:00Z",
},
create=True,
)
assert emoji1.shortcode == "emoji1"
emoji2 = Emoji.by_ap_tag(
identity.domain,
{
"icon": {
"type": "Image",
"url": "https://example.com/emoji/custom/emoji2.png",
"mediaType": "image/png",
},
"id": "https://example.com/emoji/custom/emoji2.png",
"nameMap": {"und": ":emoji2:"},
"type": "Emoji",
"updated": "1970-01-01T00:00:00Z",
},
create=True,
)
assert emoji2.shortcode == "emoji2"