summaryrefslogtreecommitdiffstats
path: root/activities/models/fan_out.py
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-13 18:42:47 -0700
committerAndrew Godwin2022-11-13 18:43:09 -0700
commitddb3436275d3f02183f515c38cd3193cd1dfe2f4 (patch)
tree8902d4f085ad6d8323f43af20ca497d291e4d28a /activities/models/fan_out.py
parent68c156fd2758da5831bd83bfb1249dd014d78177 (diff)
downloadtakahe-ddb3436275d3f02183f515c38cd3193cd1dfe2f4.tar.gz
takahe-ddb3436275d3f02183f515c38cd3193cd1dfe2f4.tar.bz2
takahe-ddb3436275d3f02183f515c38cd3193cd1dfe2f4.zip
Boosting! Incoming, anyway.
Diffstat (limited to 'activities/models/fan_out.py')
-rw-r--r--activities/models/fan_out.py53
1 files changed, 33 insertions, 20 deletions
diff --git a/activities/models/fan_out.py b/activities/models/fan_out.py
index 958fbe2..dbe86c0 100644
--- a/activities/models/fan_out.py
+++ b/activities/models/fan_out.py
@@ -19,23 +19,27 @@ class FanOutStates(StateGraph):
Sends the fan-out to the right inbox.
"""
fan_out = await instance.afetch_full()
- if fan_out.identity.local:
- # Make a timeline event directly
- await sync_to_async(TimelineEvent.add_post)(
- identity=fan_out.identity,
- post=fan_out.subject_post,
- )
+ # Handle Posts
+ if fan_out.type == FanOut.Types.post:
+ if fan_out.identity.local:
+ # Make a timeline event directly
+ await sync_to_async(TimelineEvent.add_post)(
+ identity=fan_out.identity,
+ post=fan_out.subject_post,
+ )
+ else:
+ # Send it to the remote inbox
+ post = await fan_out.subject_post.afetch_full()
+ # Sign it and send it
+ await HttpSignature.signed_request(
+ uri=fan_out.identity.inbox_uri,
+ body=canonicalise(post.to_create_ap()),
+ private_key=post.author.private_key,
+ key_id=post.author.public_key_id,
+ )
+ return cls.sent
else:
- # Send it to the remote inbox
- post = await fan_out.subject_post.afetch_full()
- # Sign it and send it
- await HttpSignature.signed_request(
- uri=fan_out.identity.inbox_uri,
- body=canonicalise(post.to_create_ap()),
- private_key=post.author.private_key,
- key_id=post.author.public_key_id,
- )
- return cls.sent
+ raise ValueError(f"Cannot fan out with type {fan_out.type}")
class FanOut(StatorModel):
@@ -45,7 +49,7 @@ class FanOut(StatorModel):
class Types(models.TextChoices):
post = "post"
- boost = "boost"
+ interaction = "interaction"
state = StateField(FanOutStates)
@@ -67,6 +71,13 @@ class FanOut(StatorModel):
null=True,
related_name="fan_outs",
)
+ subject_post_interaction = models.ForeignKey(
+ "activities.PostInteraction",
+ on_delete=models.CASCADE,
+ blank=True,
+ null=True,
+ related_name="fan_outs",
+ )
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
@@ -77,6 +88,8 @@ class FanOut(StatorModel):
"""
Returns a version of the object with all relations pre-loaded
"""
- return await FanOut.objects.select_related("identity", "subject_post").aget(
- pk=self.pk
- )
+ return await FanOut.objects.select_related(
+ "identity",
+ "subject_post",
+ "subject_post_interaction",
+ ).aget(pk=self.pk)