From e1e05c799d026ad3c61e1056dde8d6dc6962dac1 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 24 Mar 2023 18:08:55 +0200 Subject: [PATCH] dont barf up the whole comment chain when clicking "more comments" in /@/comments --- files/assets/js/comments.js | 2 +- files/assets/js/more_comments.js | 12 ++++++++-- files/routes/users.py | 39 +++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/files/assets/js/comments.js b/files/assets/js/comments.js index 4c14db065..b2ac7ee2a 100644 --- a/files/assets/js/comments.js +++ b/files/assets/js/comments.js @@ -37,6 +37,6 @@ function collapse_comment(id) { } const ta = document.getElementById('markdown-c_'+id); - if (!ta.classList.contains('d-none')) + if (ta && !ta.classList.contains('d-none')) expandMarkdown(`c_${id}`) }; diff --git a/files/assets/js/more_comments.js b/files/assets/js/more_comments.js index e0f008b43..cf1873a48 100644 --- a/files/assets/js/more_comments.js +++ b/files/assets/js/more_comments.js @@ -6,7 +6,14 @@ function more_comments(cid, sort) { form.append("formkey", formkey()); form.append("sort", sort); const xhr = new XMLHttpRequest(); - xhr.open("get", `/more_comments/${cid}`); + + let url; + if (location.pathname.startsWith('/@') && location.pathname.endsWith('/comments')) + url = location.pathname.replace("/comments", `/more_comments/${cid}`) + else + url = `/more_comments/${cid}` + + xhr.open("get", url); xhr.setRequestHeader('xhr', 'xhr'); xhr.onload=function(){ if (xhr.status==200) { @@ -15,7 +22,8 @@ function more_comments(cid, sort) { register_new_elements(e); bs_trigger(e) - highlight_unread("old-comment-counts") + if (typeof highlight_unread === "function") + highlight_unread("old-comment-counts") } btn.disabled = false; } diff --git a/files/routes/users.py b/files/routes/users.py index 67f4bf5be..9e4ee2871 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1031,6 +1031,7 @@ def u_username_comments(username, v=None): ids = old_ids listing = [] + comments.reverse() for x in comments: if x.replies2 == None: x.replies2 = [] @@ -1053,7 +1054,10 @@ def u_username_comments(username, v=None): x.parent_comment.replies2.append(x) x.parent_comment.replies2.sort(key=lambda x: x.created_utc, reverse=True) continue - listing.append(x) + if x.top_comment_id not in [x.id for x in listing]: + listing.append(x) + + listing.reverse() ids.update([x.id for x in listing]) @@ -1065,6 +1069,39 @@ def u_username_comments(username, v=None): return render_template("userpage/comments.html", u=u, v=v, listing=listing, page=page, sort=sort, t=t, next_exists=next_exists, is_following=is_following, standalone=True, render_replies=True) +@app.get("/@/more_comments/") +@limiter.limit(DEFAULT_RATELIMIT) +@auth_desired_with_logingate +def profile_more_comments(v, cid, username): + comments = g.db.query(Comment).filter( + Comment.top_comment_id == get_comment(cid).top_comment_id, + Comment.author_id == get_user(username).id, + Comment.level > 9, + ).all() + + listing = [] + ids = set() + + for x in comments: + while x.parent_comment_id != cid and x.level > 9: + if x.id in ids: break + ids.add(x.id) + + if x.parent_comment.replies2 == None: + x.parent_comment.replies2 = [] + x.parent_comment.replies2.append(x) + + x = x.parent_comment + + ids.add(x.id) + + if x not in listing and x.parent_comment_id == cid: + listing.append(x) + + if v: + output = get_comments_v_properties(v, None, Comment.id.in_(ids))[1] + + return render_template("comments.html", v=v, comments=listing, render_replies=True) @app.get("/@/info") @limiter.limit(DEFAULT_RATELIMIT)