summaryrefslogtreecommitdiffstats
path: root/activities/models
diff options
context:
space:
mode:
Diffstat (limited to 'activities/models')
-rw-r--r--activities/models/hashtag.py7
-rw-r--r--activities/models/post.py2
-rw-r--r--activities/models/timeline_event.py25
3 files changed, 33 insertions, 1 deletions
diff --git a/activities/models/hashtag.py b/activities/models/hashtag.py
index 162f8b4..4e1a735 100644
--- a/activities/models/hashtag.py
+++ b/activities/models/hashtag.py
@@ -185,3 +185,10 @@ class Hashtag(StatorModel):
return f'<a class="hashtag" href="/tags/{hashtag.lower()}/">#{hashtag}</a>'
return mark_safe(Hashtag.hashtag_regex.sub(replacer, content))
+
+ def to_mastodon_json(self):
+ return {
+ "name": self.hashtag,
+ "url": self.urls.view.full(),
+ "history": [],
+ }
diff --git a/activities/models/post.py b/activities/models/post.py
index 1e372c2..16e798c 100644
--- a/activities/models/post.py
+++ b/activities/models/post.py
@@ -262,7 +262,7 @@ class Post(StatorModel):
r"(^|[^\w\d\-_])@([\w\d\-_]+(?:@[\w\d\-_]+\.[\w\d\-_\.]+)?)"
)
- def linkify_mentions(self, content, local=False):
+ def linkify_mentions(self, content: str, local: bool = False) -> str:
"""
Links mentions _in the context of the post_ - as in, using the mentions
property as the only source (as we might be doing this without other
diff --git a/activities/models/timeline_event.py b/activities/models/timeline_event.py
index e598e3f..30d473d 100644
--- a/activities/models/timeline_event.py
+++ b/activities/models/timeline_event.py
@@ -1,5 +1,7 @@
from django.db import models
+from core.ld import format_ld_date
+
class TimelineEvent(models.Model):
"""
@@ -143,3 +145,26 @@ class TimelineEvent(models.Model):
subject_post_id=interaction.post_id,
subject_identity_id=interaction.identity_id,
).delete()
+
+ ### Mastodon Client API ###
+
+ def to_mastodon_notification_json(self):
+ result = {
+ "id": self.pk,
+ "created_at": format_ld_date(self.created),
+ "account": self.subject_identity.to_mastodon_json(),
+ }
+ if self.type == self.Types.liked:
+ result["type"] = "favourite"
+ result["status"] = self.subject_post.to_mastodon_json()
+ elif self.type == self.Types.boosted:
+ result["type"] = "reblog"
+ result["status"] = self.subject_post.to_mastodon_json()
+ elif self.type == self.Types.mentioned:
+ result["type"] = "mention"
+ result["status"] = self.subject_post.to_mastodon_json()
+ elif self.type == self.Types.followed:
+ result["type"] = "follow"
+ else:
+ raise ValueError(f"Cannot convert {self.type} to notification JSON")
+ return result