summaryrefslogtreecommitdiffstats
path: root/activities/models
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-15 11:56:48 -0700
committerAndrew Godwin2022-12-15 12:26:44 -0700
commit5e912ecac5aa39f2d5dbecee792665d5743a77b9 (patch)
tree776f9c8654946374a2675129bf232102338273cc /activities/models
parent61fbda0ebf8b1ca7f6ac7d8515b1bd49690f48ab (diff)
downloadtakahe-5e912ecac5aa39f2d5dbecee792665d5743a77b9.tar.gz
takahe-5e912ecac5aa39f2d5dbecee792665d5743a77b9.tar.bz2
takahe-5e912ecac5aa39f2d5dbecee792665d5743a77b9.zip
Fix outbound emoji federation
Diffstat (limited to 'activities/models')
-rw-r--r--activities/models/emoji.py23
-rw-r--r--activities/models/post.py6
2 files changed, 15 insertions, 14 deletions
diff --git a/activities/models/emoji.py b/activities/models/emoji.py
index 00f6e67..96b9725 100644
--- a/activities/models/emoji.py
+++ b/activities/models/emoji.py
@@ -45,15 +45,16 @@ class EmojiStates(StateGraph):
class EmojiQuerySet(models.QuerySet):
def usable(self, domain: Domain | None = None):
- public_q = models.Q(public=True)
- if Config.system.emoji_unreviewed_are_public:
- public_q |= models.Q(public__isnull=True)
-
- qs = self.filter(public_q)
+ if domain is None or domain.local:
+ visible_q = models.Q(local=True)
+ else:
+ visible_q = models.Q(public=True)
+ if Config.system.emoji_unreviewed_are_public:
+ visible_q |= models.Q(public__isnull=True)
+
+ qs = self.filter(visible_q)
if domain:
- if domain.local:
- qs = qs.filter(local=True)
- else:
+ if not domain.local:
qs = qs.filter(domain=domain)
return qs
@@ -194,7 +195,7 @@ class Emoji(StatorModel):
return mark_safe(Emoji.emoji_regex.sub(replacer, content))
@classmethod
- def emojis_from_content(cls, content: str, domain: Domain) -> list[str]:
+ def emojis_from_content(cls, content: str, domain: Domain | None) -> list[str]:
"""
Return a parsed and sanitized of emoji found in content without
the surrounding ':'.
@@ -202,7 +203,7 @@ class Emoji(StatorModel):
emoji_hits = cls.emoji_regex.findall(strip_html(content))
emojis = sorted({emoji.lower() for emoji in emoji_hits})
return list(
- cls.objects.filter(local=domain is None)
+ cls.objects.filter(local=(domain is None) or domain.local)
.usable(domain)
.filter(shortcode__in=emojis)
)
@@ -213,7 +214,7 @@ class Emoji(StatorModel):
http://joinmastodon.org/ns#Emoji
"""
return {
- "id": self.object_uri,
+ "id": self.object_uri or f"https://{settings.MAIN_DOMAIN}/emoji/{self.pk}/",
"type": "Emoji",
"name": self.shortcode,
"icon": {
diff --git a/activities/models/post.py b/activities/models/post.py
index 2b0a7c2..97ee0e0 100644
--- a/activities/models/post.py
+++ b/activities/models/post.py
@@ -363,7 +363,7 @@ class Post(StatorModel):
"""
return (
await Post.objects.select_related("author", "author__domain")
- .prefetch_related("mentions", "mentions__domain", "attachments")
+ .prefetch_related("mentions", "mentions__domain", "attachments", "emojis")
.aget(pk=self.pk)
)
@@ -391,7 +391,7 @@ class Post(StatorModel):
# Find hashtags in this post
hashtags = Hashtag.hashtags_from_content(content) or None
# Find emoji in this post
- emojis = Emoji.emojis_from_content(content, author.domain)
+ emojis = Emoji.emojis_from_content(content, None)
# Strip all HTML and apply linebreaks filter
content = linebreaks_filter(strip_html(content))
# Make the Post object
@@ -430,7 +430,7 @@ class Post(StatorModel):
self.edited = timezone.now()
self.hashtags = Hashtag.hashtags_from_content(content) or None
self.mentions.set(self.mentions_from_content(content, self.author))
- self.emojis.set(Emoji.emojis_from_content(content, self.author.domain))
+ self.emojis.set(Emoji.emojis_from_content(content, None))
self.attachments.set(attachments or [])
self.save()