From ef94e057f7032386049e0a3cfc83fcbcc3a93617 Mon Sep 17 00:00:00 2001
From: Jason McBrayer <jmcbray@carcosa.net>
Date: Fri, 19 Jul 2019 09:56:52 -0400
Subject: [PATCH] Always load full threads

This is the first step in the real-threading mod that I'm
working on.
---
 brutaldon/templates/main/thread.html | 18 ++++++++----------
 brutaldon/views.py                   | 20 ++++++++++++--------
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/brutaldon/templates/main/thread.html b/brutaldon/templates/main/thread.html
index 7566bd9..7c05fe4 100644
--- a/brutaldon/templates/main/thread.html
+++ b/brutaldon/templates/main/thread.html
@@ -18,21 +18,19 @@ mastodon.status_context(<numerical id>)
     <h1 id="title" class="title">
         Thread
     </h1>
-    {% for ancestor in ancestors %}
-    {% include "main/toot_partial.html" with toot=ancestor %}
-    <hr class="is-hidden">
-    {% endfor %}
-    {% include "main/toot_partial.html" with toot=toot active=True %}
-    <hr class="is-hidden">
+    {% include "main/toot_partial.html" with toot=root %}
     {% for descendant in descendants %}
-    {% include "main/toot_partial.html" with toot=descendant %}
-    <hr class="is-hidden">
+        {% if descendant == toot %}
+            {% include "main/toot_partial.html" with toot=toot active=True %}
+        {% else %}
+            {% include "main/toot_partial.html" with toot=descendant %}
+        {% endif %}
+        <hr class="is-hidden">
     {% endfor %}
 
     {% if not preferences.no_javascript %}
         <script type="application/javascript">
-            Intercooler.ready(expandCWButtonPrepare);
+         Intercooler.ready(expandCWButtonPrepare);
         </script>
     {% endif %}
 {% endblock %}
-
diff --git a/brutaldon/views.py b/brutaldon/views.py
index abc1906..e98c296 100644
--- a/brutaldon/views.py
+++ b/brutaldon/views.py
@@ -608,16 +608,19 @@ def note(request, next=None, prev=None):
 @br_login_required
 def thread(request, id):
     account, mastodon = get_usercontext(request)
+    toot = mastodon.status(id)
+    root = toot
     try:
         context = mastodon.status_context(id)
+        if context.ancestors and len(context.ancestors) > 0:
+            root = context.ancestors[0]
+            context = mastodon.status_context(context.ancestors[0])
     except MastodonNotFoundError:
         raise Http404(_("Thread not found; the message may have been deleted."))
-    toot = mastodon.status(id)
     notifications = _notes_count(account, mastodon)
     filters = get_filters(mastodon, context="thread")
 
     # Apply filters
-    ancestors = [x for x in context.ancestors if not toot_matches_filters(x, filters)]
     descendants = [
         x for x in context.descendants if not toot_matches_filters(x, filters)
     ]
@@ -628,7 +631,7 @@ def thread(request, id):
         {
             "context": context,
             "toot": toot,
-            "ancestors": ancestors,
+            "root": root,
             "descendants": descendants,
             "own_acct": request.session["active_user"],
             "notifications": notifications,
@@ -1617,6 +1620,7 @@ def accounts(request, id=None):
                 },
             )
 
+
 @br_login_required
 def vote(request, id):
     if request.method == "GET":
@@ -1629,16 +1633,16 @@ def vote(request, id):
             return redirect("thread", id)
         # radio buttons
         if "poll-single" in request.POST.keys():
-            mastodon.poll_vote(poll.id, request.POST['poll-single'])
+            mastodon.poll_vote(poll.id, request.POST["poll-single"])
         # checkboxes
         else:
-            values = [x for x in request.POST.getlist('poll-multiple')]
+            values = [x for x in request.POST.getlist("poll-multiple")]
             if values:
                 mastodon.poll_vote(poll.id, values)
 
         if request.POST.get("ic-request"):
-            return render(request,
-                          "main/toot_partial.html",
-                          {"toot": mastodon.status(id) })
+            return render(
+                request, "main/toot_partial.html", {"toot": mastodon.status(id)}
+            )
         else:
             return redirect("thread", id)