summaryrefslogtreecommitdiffstats
path: root/activities/views
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-11 12:37:28 -0700
committerAndrew Godwin2022-12-12 11:56:49 -0700
commit20239b5cb7455d593680b17d2d80d2a4850c524d (patch)
tree1c5705837e17bca50920848d00bfcf1f7c2313af /activities/views
parentfc8a21fc5c6809ea115092eeec57e09e984cdd76 (diff)
downloadtakahe-20239b5cb7455d593680b17d2d80d2a4850c524d.tar.gz
takahe-20239b5cb7455d593680b17d2d80d2a4850c524d.tar.bz2
takahe-20239b5cb7455d593680b17d2d80d2a4850c524d.zip
Basic post mutation
Diffstat (limited to 'activities/views')
-rw-r--r--activities/views/posts.py32
1 files changed, 5 insertions, 27 deletions
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(