From ddb3436275d3f02183f515c38cd3193cd1dfe2f4 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 13 Nov 2022 18:42:47 -0700 Subject: Boosting! Incoming, anyway. --- activities/models/fan_out.py | 53 +++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'activities/models/fan_out.py') 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) -- cgit v1.2.3