summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activities/models/post.py1
-rw-r--r--activities/views/posts.py56
-rw-r--r--takahe/urls.py1
-rw-r--r--templates/activities/_post.html2
-rw-r--r--templates/activities/post_delete.html14
5 files changed, 67 insertions, 7 deletions
diff --git a/activities/models/post.py b/activities/models/post.py
index c8165d6..642842c 100644
--- a/activities/models/post.py
+++ b/activities/models/post.py
@@ -138,6 +138,7 @@ class Post(StatorModel):
action_unlike = "{view}unlike/"
action_boost = "{view}boost/"
action_unboost = "{view}unboost/"
+ action_delete = "{view}delete/"
action_reply = "/compose/?reply_to={self.id}"
def get_scheme(self, url):
diff --git a/activities/views/posts.py b/activities/views/posts.py
index a53d401..268a3fe 100644
--- a/activities/views/posts.py
+++ b/activities/views/posts.py
@@ -1,4 +1,5 @@
from django import forms
+from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.decorators import method_decorator
from django.views.generic import FormView, TemplateView, View
@@ -7,8 +8,10 @@ from activities.models import (
Post,
PostInteraction,
PostInteractionStates,
+ PostStates,
TimelineEvent,
)
+from core.ld import canonicalise
from core.models import Config
from users.decorators import identity_required
from users.shortcuts import by_handle_or_404
@@ -18,18 +21,38 @@ class Individual(TemplateView):
template_name = "activities/post.html"
- def get_context_data(self, handle, post_id):
- identity = by_handle_or_404(self.request, handle, local=False)
- post = get_object_or_404(identity.posts, pk=post_id)
+ def get(self, request, handle, post_id):
+ self.identity = by_handle_or_404(self.request, handle, local=False)
+ self.post_obj = get_object_or_404(self.identity.posts, pk=post_id)
+ # If they're coming in looking for JSON, they want the actor
+ accept = request.META.get("HTTP_ACCEPT", "text/html").lower()
+ if (
+ "application/json" in accept
+ or "application/ld" in accept
+ or "application/activity" in accept
+ ):
+ # Return post JSON
+ return self.serve_object()
+ else:
+ # Show normal page
+ return super().get(request)
+
+ def get_context_data(self):
return {
- "identity": identity,
- "post": post,
+ "identity": self.identity,
+ "post": self.post_obj,
"interactions": PostInteraction.get_post_interactions(
- [post],
+ [self.post_obj],
self.request.identity,
),
}
+ def serve_object(self):
+ # If this not a local post, redirect to its canonical URI
+ if not self.post_obj.local:
+ return redirect(self.post_obj.object_uri)
+ return JsonResponse(canonicalise(self.post_obj.to_ap(), include_security=True))
+
@method_decorator(identity_required, name="dispatch")
class Like(View):
@@ -112,6 +135,27 @@ class Boost(View):
@method_decorator(identity_required, name="dispatch")
+class Delete(TemplateView):
+ """
+ Deletes a post
+ """
+
+ template_name = "activities/post_delete.html"
+
+ def dispatch(self, request, handle, post_id):
+ self.identity = by_handle_or_404(self.request, handle, local=False)
+ self.post_obj = get_object_or_404(self.identity.posts, pk=post_id)
+ return super().dispatch(request)
+
+ def get_context_data(self):
+ return {"post": self.post_obj}
+
+ def post(self, request):
+ self.post_obj.transition_perform(PostStates.deleted)
+ return redirect("/")
+
+
+@method_decorator(identity_required, name="dispatch")
class Compose(FormView):
template_name = "activities/compose.html"
diff --git a/takahe/urls.py b/takahe/urls.py
index 614ec3b..ddffa68 100644
--- a/takahe/urls.py
+++ b/takahe/urls.py
@@ -94,6 +94,7 @@ urlpatterns = [
path("@<handle>/posts/<int:post_id>/unlike/", posts.Like.as_view(undo=True)),
path("@<handle>/posts/<int:post_id>/boost/", posts.Boost.as_view()),
path("@<handle>/posts/<int:post_id>/unboost/", posts.Boost.as_view(undo=True)),
+ path("@<handle>/posts/<int:post_id>/delete/", posts.Delete.as_view()),
# Authentication
path("auth/login/", auth.Login.as_view(), name="login"),
path("auth/logout/", auth.Logout.as_view(), name="logout"),
diff --git a/templates/activities/_post.html b/templates/activities/_post.html
index e109e9c..06aa3f7 100644
--- a/templates/activities/_post.html
+++ b/templates/activities/_post.html
@@ -34,7 +34,7 @@
<i class="fa-solid fa-caret-down"></i>
</a>
<menu>
- <a>
+ <a href="{{ post.urls.action_delete }}">
<i class="fa-solid fa-trash"></i> Delete
</a>
</menu>
diff --git a/templates/activities/post_delete.html b/templates/activities/post_delete.html
new file mode 100644
index 0000000..1566399
--- /dev/null
+++ b/templates/activities/post_delete.html
@@ -0,0 +1,14 @@
+{% extends "base.html" %}
+
+{% block title %}Delete Post{% endblock %}
+
+{% block content %}
+ <h1>Delete this post?</h1>
+ <form action="." method="POST">
+ {% csrf_token %}
+ <a class="button" onclick="history.back()">Cancel</a>
+ <button class="delete">Delete</button>
+ </form>
+
+ {% include "activities/_post.html" %}
+{% endblock %}