summaryrefslogtreecommitdiffstats
path: root/activities/models/fan_out.py
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-15 18:30:30 -0700
committerAndrew Godwin2022-11-15 15:30:32 -0700
commit20e63023bb0d3c7e4cb36b91b73e79f51889cc90 (patch)
tree96c99139f03550e35902440cd321290bc47f8f0f /activities/models/fan_out.py
parent4aa92744aea6097ffb784ca7de6bd95cc599988d (diff)
downloadtakahe-20e63023bb0d3c7e4cb36b91b73e79f51889cc90.tar.gz
takahe-20e63023bb0d3c7e4cb36b91b73e79f51889cc90.tar.bz2
takahe-20e63023bb0d3c7e4cb36b91b73e79f51889cc90.zip
Get outbound likes/boosts and their undos working
Diffstat (limited to 'activities/models/fan_out.py')
-rw-r--r--activities/models/fan_out.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/activities/models/fan_out.py b/activities/models/fan_out.py
index dbe86c0..771be19 100644
--- a/activities/models/fan_out.py
+++ b/activities/models/fan_out.py
@@ -38,6 +38,40 @@ class FanOutStates(StateGraph):
key_id=post.author.public_key_id,
)
return cls.sent
+ # Handle boosts/likes
+ elif fan_out.type == FanOut.Types.interaction:
+ interaction = await fan_out.subject_post_interaction.afetch_full()
+ if fan_out.identity.local:
+ # Make a timeline event directly
+ await sync_to_async(TimelineEvent.add_post_interaction)(
+ identity=fan_out.identity,
+ interaction=interaction,
+ )
+ else:
+ # Send it to the remote inbox
+ await HttpSignature.signed_request(
+ uri=fan_out.identity.inbox_uri,
+ body=canonicalise(interaction.to_ap()),
+ private_key=interaction.identity.private_key,
+ key_id=interaction.identity.public_key_id,
+ )
+ # Handle undoing boosts/likes
+ elif fan_out.type == FanOut.Types.undo_interaction:
+ interaction = await fan_out.subject_post_interaction.afetch_full()
+ if fan_out.identity.local:
+ # Delete any local timeline events
+ await sync_to_async(TimelineEvent.delete_post_interaction)(
+ identity=fan_out.identity,
+ interaction=interaction,
+ )
+ else:
+ # Send an undo to the remote inbox
+ await HttpSignature.signed_request(
+ uri=fan_out.identity.inbox_uri,
+ body=canonicalise(interaction.to_undo_ap()),
+ private_key=interaction.identity.private_key,
+ key_id=interaction.identity.public_key_id,
+ )
else:
raise ValueError(f"Cannot fan out with type {fan_out.type}")
@@ -50,6 +84,7 @@ class FanOut(StatorModel):
class Types(models.TextChoices):
post = "post"
interaction = "interaction"
+ undo_interaction = "undo_interaction"
state = StateField(FanOutStates)