From af3142ac3adb0d1f31d160edcb6d076b293020b1 Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Thu, 15 Dec 2022 02:50:54 -0500 Subject: Basic Emoji suppport (#157) --- users/models/identity.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'users/models') diff --git a/users/models/identity.py b/users/models/identity.py index 1239ca1..7898b4a 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -169,16 +169,20 @@ class Identity(StatorModel): @property def safe_summary(self): - return sanitize_post(self.summary) + from activities.templatetags.emoji_tags import imageify_emojis + + return imageify_emojis(sanitize_post(self.summary), self.domain) @property def safe_metadata(self): + from activities.templatetags.emoji_tags import imageify_emojis + if not self.metadata: return [] return [ { "name": data["name"], - "value": strip_html(data["value"]), + "value": imageify_emojis(strip_html(data["value"]), self.domain), } for data in self.metadata ] @@ -240,6 +244,15 @@ class Identity(StatorModel): def name_or_handle(self): return self.name or self.handle + @cached_property + def html_name_or_handle(self): + """ + Return the name_or_handle with any HTML substitutions made + """ + from activities.templatetags.emoji_tags import imageify_emojis + + return imageify_emojis(self.name_or_handle, self.domain) + @property def handle(self): if self.username is None: @@ -303,6 +316,17 @@ class Identity(StatorModel): } return response + def to_ap_tag(self): + """ + Return this Identity as an ActivityPub Tag + http://joinmastodon.org/ns#Mention + """ + return { + "href": self.actor_uri, + "name": "@" + self.handle, + "type": "Mention", + } + ### ActivityPub (inbound) ### @classmethod @@ -470,7 +494,15 @@ class Identity(StatorModel): ### Mastodon Client API ### def to_mastodon_json(self): + from activities.models import Emoji + header_image = self.local_image_url() + metadata_value_text = ( + " ".join([m["value"] for m in self.metadata]) if self.metadata else "" + ) + emojis = Emoji.emojis_from_content( + f"{self.name} {self.summary} {metadata_value_text}", self.domain + ) return { "id": self.pk, "username": self.username, @@ -491,7 +523,7 @@ class Identity(StatorModel): if self.metadata else [] ), - "emojis": [], + "emojis": [emoji.to_mastodon_json() for emoji in emojis], "bot": False, "group": False, "discoverable": self.discoverable, -- cgit v1.2.3