From 20239b5cb7455d593680b17d2d80d2a4850c524d Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 11 Dec 2022 12:37:28 -0700 Subject: Basic post mutation --- activities/views/posts.py | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) (limited to 'activities/views') diff --git a/activities/views/posts.py b/activities/views/posts.py index ccc38fc..e285c7e 100644 --- a/activities/views/posts.py +++ b/activities/views/posts.py @@ -6,7 +6,7 @@ from django.utils.decorators import method_decorator from django.views.decorators.vary import vary_on_headers from django.views.generic import TemplateView, View -from activities.models import Post, PostInteraction, PostInteractionStates, PostStates +from activities.models import Post, PostInteraction, PostStates from core.decorators import cache_page_by_ap_json from core.ld import canonicalise from users.decorators import identity_required @@ -94,20 +94,9 @@ class Like(View): identity.posts.prefetch_related("attachments"), pk=post_id ) if self.undo: - # Undo any likes on the post - for interaction in PostInteraction.objects.filter( - type=PostInteraction.Types.like, - identity=request.identity, - post=post, - ): - interaction.transition_perform(PostInteractionStates.undone) + post.unlike_as(self.request.identity) else: - # Make a like on this post if we didn't already - PostInteraction.objects.get_or_create( - type=PostInteraction.Types.like, - identity=request.identity, - post=post, - ) + post.like_as(self.request.identity) # Return either a redirect or a HTMX snippet if request.htmx: return render( @@ -133,20 +122,9 @@ class Boost(View): identity = by_handle_or_404(self.request, handle, local=False) post = get_object_or_404(identity.posts, pk=post_id) if self.undo: - # Undo any boosts on the post - for interaction in PostInteraction.objects.filter( - type=PostInteraction.Types.boost, - identity=request.identity, - post=post, - ): - interaction.transition_perform(PostInteractionStates.undone) + post.unboost_as(request.identity) else: - # Make a boost on this post if we didn't already - PostInteraction.objects.get_or_create( - type=PostInteraction.Types.boost, - identity=request.identity, - post=post, - ) + post.boost_as(request.identity) # Return either a redirect or a HTMX snippet if request.htmx: return render( -- cgit v1.2.3