VIEW MORE

remotes/1693045480750635534/spooky-22
Aevann1 2021-12-05 19:30:32 +02:00
parent 896290df31
commit 944b0cc77e
6 changed files with 104 additions and 9 deletions

View File

@ -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/<pid>/<sort>/<offset>")
@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/<pid>")
@limiter.limit("1/second")

View File

@ -749,7 +749,7 @@
{% if v %}
<script src="https://cdn.jsdelivr.net/npm/marked@3.0.8/lib/marked.min.js"></script>
<script src="/assets/js/comments_v.js?v=80"></script>
<script src="/assets/js/comments_v.js?v=81"></script>
{% endif %}
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>

View File

@ -84,7 +84,7 @@
</div>
</div>
<script src="/assets/js/emoji_modal.js?v=133"></script>
<script src="/assets/js/emoji_modal.js?v=136"></script>
<style>
a.emojitab {

View File

@ -6,7 +6,7 @@
<script>
block_user=function() {
function block_user() {
var exileForm = document.getElementById("exile-form");

View File

@ -15,7 +15,7 @@
{% if v and (v.id == p.author_id or v.admin_level > 1 and v.admin_level > 2) %}
<script>
togglePostEdit=function(id){
function togglePostEdit(id){
body=document.getElementById("post-body");
title=document.getElementById("post-title");
@ -823,10 +823,25 @@
</div>
{% if offset %}
<script>
function viewmore() {
var form = new FormData();
var xhr = new XMLHttpRequest();
xhr.open("post", "/viewmore/{{p.id}}/{{sort}}/{{offset}}");
xhr.withCredentials=true;
xhr.onload=function(){
if (xhr.status==200) {
document.getElementById("viewmore").innerHTML = xhr.response;
}
}
xhr.send(form)
}
</script>
<br>
<a class="pt-2" href="{{request.path}}?sort={{sort}}&offset={{offset}}">VIEW MORE</a>
<div id="viewmore"><a class="btn btn-primary" href="javascript:void(0)" onclick="viewmore()">VIEW MORE COMMENTS</a></div>
{% endif %}
{% elif not p.replies and p.deleted_utc == 0 %}
<div class="comment-section text-center py-7">
<span class="fa-stack fa-2x text-muted mb-4">
@ -884,7 +899,7 @@
{% if not p.comment_count %}
{% if v %}
<script src="/assets/js/comments_v.js?v=80"></script>
<script src="/assets/js/comments_v.js?v=81"></script>
{% include "award_modal.html" %}
{% include "emoji_modal.html" %}
{% include "gif_modal.html" %}

View File

@ -177,7 +177,7 @@
<script src="https://cdn.jsdelivr.net/npm/marked@3.0.8/lib/marked.min.js"></script>
<script src="/assets/js/submit.js?v=72"></script>
<script src="/assets/js/submit.js?v=73"></script>
{% include "emoji_modal.html" %}