diff options
author | Andrew Godwin | 2022-11-16 21:42:25 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-16 21:42:25 -0700 |
commit | 5b34ea46c3f458a174c5443714ade43c21defdac (patch) | |
tree | e41dda2218cee559268f99a802210f7507f47b02 /activities/models/post_interaction.py | |
parent | 9d97fc92d82289301896c88f8c828321aa99701d (diff) | |
download | takahe-5b34ea46c3f458a174c5443714ade43c21defdac.tar.gz takahe-5b34ea46c3f458a174c5443714ade43c21defdac.tar.bz2 takahe-5b34ea46c3f458a174c5443714ade43c21defdac.zip |
Call it admin rather than system settings
Diffstat (limited to 'activities/models/post_interaction.py')
-rw-r--r-- | activities/models/post_interaction.py | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/activities/models/post_interaction.py b/activities/models/post_interaction.py index 4f1eb03..e9248e8 100644 --- a/activities/models/post_interaction.py +++ b/activities/models/post_interaction.py @@ -1,6 +1,6 @@ from typing import Dict -from django.db import models +from django.db import models, transaction from django.utils import timezone from activities.models.fan_out import FanOut @@ -272,31 +272,33 @@ class PostInteraction(StatorModel): """ Handles an incoming announce/like """ - # Create it - interaction = cls.by_ap(data, create=True) - # Boosts (announces) go to everyone who follows locally - if interaction.type == cls.Types.boost: - for follow in Follow.objects.filter( - target=interaction.identity, source__local=True - ): - TimelineEvent.add_post_interaction(follow.source, interaction) - # Likes go to just the author of the post - elif interaction.type == cls.Types.like: - TimelineEvent.add_post_interaction(interaction.post.author, interaction) - # Force it into fanned_out as it's not ours - interaction.transition_perform(PostInteractionStates.fanned_out) + with transaction.atomic(): + # Create it + interaction = cls.by_ap(data, create=True) + # Boosts (announces) go to everyone who follows locally + if interaction.type == cls.Types.boost: + for follow in Follow.objects.filter( + target=interaction.identity, source__local=True + ): + TimelineEvent.add_post_interaction(follow.source, interaction) + # Likes go to just the author of the post + elif interaction.type == cls.Types.like: + 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) + with transaction.atomic(): + # 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) |