diff --git a/bookwyrm/templates/feed/status.html b/bookwyrm/templates/feed/status.html index 429c657d..8f354fb8 100644 --- a/bookwyrm/templates/feed/status.html +++ b/bookwyrm/templates/feed/status.html @@ -11,6 +11,13 @@
+ {% for parent in ancestors %} + {% if parent %} +
+ {% include 'snippets/status/status.html' with status=parent %} +
+ {% endif %} + {% endfor %}
{% include 'snippets/status/status.html' with status=status main=True %}
diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index b873224b..7f1bc22c 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -114,6 +114,27 @@ class Status(View): ).values_list("id", flat=True) visible_thread = list(visible_thread) + ancestors = models.Status.objects.select_subclasses().raw( + """ + WITH RECURSIVE get_thread(depth, id, path) AS ( + + SELECT 1, st.id, ARRAY[st.id] + FROM bookwyrm_status st + WHERE id = '%s' AND id = ANY(%s) + + UNION + + SELECT (gt.depth + 1), st.reply_parent_id, path || st.id + FROM get_thread gt, bookwyrm_status st + + WHERE st.id = gt.id AND depth < 5 AND st.id = ANY(%s) + + ) + + SELECT * FROM get_thread ORDER BY path DESC; + """, + params=[status.reply_parent_id or 0, visible_thread, visible_thread], + ) children = models.Status.objects.select_subclasses().raw( """ WITH RECURSIVE get_thread(depth, id, path) AS ( @@ -141,6 +162,7 @@ class Status(View): **{ "status": status, "children": children, + "ancestors": ancestors, }, } return TemplateResponse(request, "feed/status.html", data)