mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-26 09:11:00 +00:00
parent
165d84abbf
commit
d3fd365a37
4 changed files with 51 additions and 1 deletions
|
@ -114,6 +114,7 @@ class Hashtag(StatorModel):
|
||||||
objects = HashtagManager()
|
objects = HashtagManager()
|
||||||
|
|
||||||
class urls(urlman.Urls):
|
class urls(urlman.Urls):
|
||||||
|
view = "/tags/{self.hashtag}/"
|
||||||
admin = "/admin/hashtags/"
|
admin = "/admin/hashtags/"
|
||||||
admin_edit = "{admin}{self.hashtag}/"
|
admin_edit = "{admin}{self.hashtag}/"
|
||||||
timeline = "/tags/{self.hashtag}/"
|
timeline = "/tags/{self.hashtag}/"
|
||||||
|
|
|
@ -322,3 +322,42 @@ class PostInteraction(StatorModel):
|
||||||
interaction.timeline_events.all().delete()
|
interaction.timeline_events.all().delete()
|
||||||
# Force it into undone_fanned_out as it's not ours
|
# Force it into undone_fanned_out as it's not ours
|
||||||
interaction.transition_perform(PostInteractionStates.undone_fanned_out)
|
interaction.transition_perform(PostInteractionStates.undone_fanned_out)
|
||||||
|
|
||||||
|
### Mastodon API ###
|
||||||
|
|
||||||
|
def to_mastodon_status_json(self, interactions=None):
|
||||||
|
"""
|
||||||
|
This wraps Posts in a fake Status for boost interactions.
|
||||||
|
"""
|
||||||
|
if self.type != self.Types.boost:
|
||||||
|
raise ValueError(
|
||||||
|
f"Cannot make status JSON for interaction of type {self.type}"
|
||||||
|
)
|
||||||
|
# Grab our subject post JSON, and just return it if we're a post
|
||||||
|
post_json = self.post.to_mastodon_json(interactions=interactions)
|
||||||
|
return {
|
||||||
|
"id": f"interaction-{self.pk}",
|
||||||
|
"uri": post_json["uri"],
|
||||||
|
"created_at": format_ld_date(self.published),
|
||||||
|
"account": self.identity.to_mastodon_json(),
|
||||||
|
"content": "",
|
||||||
|
"visibility": post_json["visibility"],
|
||||||
|
"sensitive": post_json["sensitive"],
|
||||||
|
"spoiler_text": post_json["spoiler_text"],
|
||||||
|
"media_attachments": [],
|
||||||
|
"mentions": [],
|
||||||
|
"tags": [],
|
||||||
|
"emojis": [],
|
||||||
|
"reblogs_count": 0,
|
||||||
|
"favourites_count": 0,
|
||||||
|
"replies_count": 0,
|
||||||
|
"url": post_json["url"],
|
||||||
|
"in_reply_to_id": None,
|
||||||
|
"in_reply_to_account_id": None,
|
||||||
|
"poll": None,
|
||||||
|
"card": None,
|
||||||
|
"language": None,
|
||||||
|
"text": "",
|
||||||
|
"edited_at": None,
|
||||||
|
"reblog": post_json,
|
||||||
|
}
|
||||||
|
|
|
@ -181,3 +181,13 @@ class TimelineEvent(models.Model):
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Cannot convert {self.type} to notification JSON")
|
raise ValueError(f"Cannot convert {self.type} to notification JSON")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def to_mastodon_status_json(self, interactions=None):
|
||||||
|
if self.type == self.Types.post:
|
||||||
|
return self.subject_post.to_mastodon_json(interactions=interactions)
|
||||||
|
elif self.type == self.Types.boost:
|
||||||
|
return self.subject_post_interaction.to_mastodon_status_json(
|
||||||
|
interactions=interactions
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Cannot make status JSON for type {self.type}")
|
||||||
|
|
|
@ -41,7 +41,7 @@ def home(
|
||||||
)
|
)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
event.subject_post.to_mastodon_json(interactions=interactions)
|
event.to_mastodon_status_json(interactions=interactions)
|
||||||
for event in pager.results
|
for event in pager.results
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue