diff --git a/bookwyrm/templates/feed/status.html b/bookwyrm/templates/feed/status.html index 903ca790..429c657d 100644 --- a/bookwyrm/templates/feed/status.html +++ b/bookwyrm/templates/feed/status.html @@ -9,7 +9,19 @@ -{% include 'feed/thread.html' with status=status depth=0 max_depth=6 is_root=True direction=0 %} +
+
+
+ {% include 'snippets/status/status.html' with status=status main=True %} +
+ + {% for child in children %} +
+ {% include 'snippets/status/status.html' with status=child %} +
+ {% endfor %} +
+
{% endblock %} diff --git a/bookwyrm/templates/feed/thread.html b/bookwyrm/templates/feed/thread.html deleted file mode 100644 index c1b624e3..00000000 --- a/bookwyrm/templates/feed/thread.html +++ /dev/null @@ -1,25 +0,0 @@ -{% load status_display %} - -
-
-{% with depth=depth|add:1 %} - {% if depth <= max_depth and status.reply_parent and direction <= 0 %} - {% with direction=-1 %} - {% include 'feed/thread.html' with status=status|parent is_root=False %} - {% endwith %} - {% endif %} - - - {% include 'snippets/status/status.html' with status=status main=is_root %} -
- -{% if depth <= max_depth and direction >= 0 %} - {% for reply in status|replies %} - {% with direction=1 %} - {% include 'feed/thread.html' with status=reply is_root=False %} - {% endwith %} - {% endfor %} -{% endif %} -{% endwith %} -
- diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index 0c2647ae..f79b1515 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -109,10 +109,30 @@ class Status(View): status.to_activity(pure=not is_bookwyrm_request(request)) ) + children = 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 reply_parent_id = '%s' + + UNION + + SELECT (gt.depth + 1), st.id, path || st.id + FROM get_thread gt, bookwyrm_status st + + WHERE st.reply_parent_id = gt.id AND depth < 5 + + ) + + SELECT * FROM get_thread ORDER BY path; + """, params=[status.id]) + data = { **feed_page_data(request.user), **{ "status": status, + "children": children, }, } return TemplateResponse(request, "feed/status.html", data)