mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-22 07:10:59 +00:00
Accept incoming action undos
This commit is contained in:
parent
20e63023bb
commit
2ef709b642
2 changed files with 23 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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}"
|
||||
|
|
Loading…
Reference in a new issue