From 944b0cc77ecebaa53a417f17b5c394b1977a136a Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 5 Dec 2021 19:30:32 +0200 Subject: [PATCH] VIEW MORE --- files/routes/posts.py | 84 +++++++++++++++++++++++++++- files/templates/comments.html | 2 +- files/templates/emoji_modal.html | 2 +- files/templates/settings_blocks.html | 2 +- files/templates/submission.html | 21 ++++++- files/templates/submit.html | 2 +- 6 files changed, 104 insertions(+), 9 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 975098b93..cb48be657 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -189,8 +189,7 @@ def post_id(pid, anything=None, v=None): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - offset = int(request.values.get("offset", 0)) - if offset: comments = comments.offset(offset) + offset = 0 comments = comments.all() @@ -222,6 +221,87 @@ def post_id(pid, anything=None, v=None): else: template = "submission.html" return render_template(template, v=v, p=post, sort=sort, render_replies=True, offset=offset) +@app.post("/viewmore///") +@limiter.limit("1/second") +@auth_desired +def viewmore(v, pid, sort, offset): + if v: + votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + + blocking = v.blocking.subquery() + + blocked = v.blocked.subquery() + + comments = g.db.query( + Comment, + votes.c.vote_type, + blocking.c.id, + blocked.c.id, + ) + + if not (v and v.shadowbanned) and not (v and v.admin_level > 1): + comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None) + + comments=comments.filter(Comment.parent_submission == pid, Comment.author_id != AUTOPOLLER_ID).join( + votes, + votes.c.comment_id == Comment.id, + isouter=True + ).join( + blocking, + blocking.c.target_id == Comment.author_id, + isouter=True + ).join( + blocked, + blocked.c.user_id == Comment.author_id, + isouter=True + ) + + output = [] + for c in comments.all(): + comment = c[0] + comment.voted = c[1] or 0 + comment.is_blocking = c[2] or 0 + comment.is_blocked = c[3] or 0 + output.append(comment) + + pinned = [c[0] for c in comments.filter(Comment.is_pinned != None).all()] + + comments = comments.filter(Comment.level == 1, Comment.is_pinned == None) + + if sort == "new": + comments = comments.order_by(Comment.created_utc.desc()) + elif sort == "old": + comments = comments.order_by(Comment.created_utc.asc()) + elif sort == "controversial": + comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes) + elif sort == "top": + comments = comments.order_by(-Comment.upvotes - Comment.downvotes) + elif sort == "bottom": + comments = comments.order_by(Comment.upvotes - Comment.downvotes) + + if offset: comments = comments.offset(int(offset)) + + comments = [c[0] for c in comments.all()] + else: + comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == pid, Comment.author_id != AUTOPOLLER_ID, Comment.level == 1, Comment.is_pinned == None) + + if sort == "new": + comments = comments.order_by(Comment.created_utc.desc()) + elif sort == "old": + comments = comments.order_by(Comment.created_utc.asc()) + elif sort == "controversial": + comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes) + elif sort == "top": + comments = comments.order_by(-Comment.upvotes - Comment.downvotes) + elif sort == "bottom": + comments = comments.order_by(Comment.upvotes - Comment.downvotes) + + if offset: comments = comments.offset(int(offset)) + + comments = comments.all() + + return render_template("comments.html", v=v, comments=comments, render_replies=True) + @app.post("/edit_post/") @limiter.limit("1/second") diff --git a/files/templates/comments.html b/files/templates/comments.html index 08ca7997a..5e5964f26 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -749,7 +749,7 @@ {% if v %} - + {% endif %} diff --git a/files/templates/emoji_modal.html b/files/templates/emoji_modal.html index 79b0bc342..551514880 100644 --- a/files/templates/emoji_modal.html +++ b/files/templates/emoji_modal.html @@ -84,7 +84,7 @@ - +