summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-15 18:36:39 -0700
committerAndrew Godwin2022-11-15 15:36:40 -0700
commit2ef709b6421b238025276aa53bf1c3764696a660 (patch)
tree4366dc4d9c6baf467c6baa3fb525308be3123293
parent20e63023bb0d3c7e4cb36b91b73e79f51889cc90 (diff)
downloadtakahe-2ef709b6421b238025276aa53bf1c3764696a660.tar.gz
takahe-2ef709b6421b238025276aa53bf1c3764696a660.tar.bz2
takahe-2ef709b6421b238025276aa53bf1c3764696a660.zip
Accept incoming action undos
-rw-r--r--activities/models/post_interaction.py15
-rw-r--r--users/models/inbox_message.py8
2 files changed, 23 insertions, 0 deletions
diff --git a/activities/models/post_interaction.py b/activities/models/post_interaction.py
index ea95cdf..4f1eb03 100644
--- a/activities/models/post_interaction.py
+++ b/activities/models/post_interaction.py
@@ -285,3 +285,18 @@ class PostInteraction(StatorModel):
TimelineEvent.add_post_interaction(interaction.post.author, interaction)
# Force it into fanned_out as it's not ours
interaction.transition_perform(PostInteractionStates.fanned_out)
+
+ @classmethod
+ def handle_undo_ap(cls, data):
+ """
+ Handles an incoming undo for a announce/like
+ """
+ # Find it
+ interaction = cls.by_ap(data["object"])
+ # Verify the actor matches
+ if data["actor"] != interaction.identity.actor_uri:
+ raise ValueError("Actor mismatch on interaction undo")
+ # Delete all events that reference it
+ interaction.timeline_events.all().delete()
+ # Force it into undone_fanned_out as it's not ours
+ interaction.transition_perform(PostInteractionStates.undone_fanned_out)
diff --git a/users/models/inbox_message.py b/users/models/inbox_message.py
index b9bcfb4..55eb3cb 100644
--- a/users/models/inbox_message.py
+++ b/users/models/inbox_message.py
@@ -42,6 +42,14 @@ class InboxMessageStates(StateGraph):
match instance.message_object_type:
case "follow":
await sync_to_async(Follow.handle_undo_ap)(instance.message)
+ case "like":
+ await sync_to_async(PostInteraction.handle_undo_ap)(
+ instance.message
+ )
+ case "announce":
+ await sync_to_async(PostInteraction.handle_undo_ap)(
+ instance.message
+ )
case unknown:
raise ValueError(
f"Cannot handle activity of type undo.{unknown}"