mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-29 02:31:00 +00:00
Accept emoji using nameMap
This commit is contained in:
parent
ec3047b304
commit
e066641556
2 changed files with 53 additions and 1 deletions
|
@ -217,8 +217,16 @@ class Emoji(StatorModel):
|
||||||
if not create:
|
if not create:
|
||||||
raise KeyError(f"No emoji with ID {data['id']}", data)
|
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
|
# create
|
||||||
shortcode = data["name"].lower().strip(":")
|
shortcode = name.lower().strip(":")
|
||||||
icon = data["icon"]
|
icon = data["icon"]
|
||||||
category = (icon.get("category") or "")[:100]
|
category = (icon.get("category") or "")[:100]
|
||||||
emoji = cls.objects.create(
|
emoji = cls.objects.create(
|
||||||
|
|
44
tests/activities/models/test_emoji.py
Normal file
44
tests/activities/models/test_emoji.py
Normal 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"
|
Loading…
Reference in a new issue