diff --git a/activities/models/emoji.py b/activities/models/emoji.py index 41e7c1c..8c74c27 100644 --- a/activities/models/emoji.py +++ b/activities/models/emoji.py @@ -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( diff --git a/tests/activities/models/test_emoji.py b/tests/activities/models/test_emoji.py new file mode 100644 index 0000000..a63536b --- /dev/null +++ b/tests/activities/models/test_emoji.py @@ -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"