fd
This commit is contained in:
parent
0a769c7d4b
commit
cdda551db1
3 changed files with 26 additions and 22 deletions
|
@ -94,6 +94,10 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
||||||
blocking.c.id,
|
blocking.c.id,
|
||||||
blocked.c.id,
|
blocked.c.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not (v and v.shadowbanned) and not (v and v.admin_level == 6):
|
||||||
|
comments = comments.join(Comment.author).filter(User.shadowbanned == False)
|
||||||
|
|
||||||
if v.admin_level >=4:
|
if v.admin_level >=4:
|
||||||
comments=comments.options(joinedload(Comment.oauth_app))
|
comments=comments.options(joinedload(Comment.oauth_app))
|
||||||
|
|
||||||
|
@ -115,7 +119,6 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
||||||
|
|
||||||
for c in comments:
|
for c in comments:
|
||||||
comment = c[0]
|
comment = c[0]
|
||||||
if comment.author and comment.author.shadowbanned and not (v and v.id == comment.author_id): continue
|
|
||||||
comment.voted = c[1] or 0
|
comment.voted = c[1] or 0
|
||||||
comment._is_blocking = c[2] or 0
|
comment._is_blocking = c[2] or 0
|
||||||
comment._is_blocked = c[3] or 0
|
comment._is_blocked = c[3] or 0
|
||||||
|
|
|
@ -423,12 +423,10 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", **kwargs):
|
||||||
comments = sorted(comments.all(), key=lambda x: x.score)
|
comments = sorted(comments.all(), key=lambda x: x.score)
|
||||||
|
|
||||||
firstrange = 25 * (page - 1)
|
firstrange = 25 * (page - 1)
|
||||||
secondrange = firstrange+100
|
secondrange = firstrange+26
|
||||||
comments = comments[firstrange:secondrange]
|
comments = comments[firstrange:secondrange]
|
||||||
|
|
||||||
comments = [x.id for x in comments if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)]
|
return [x.id for x in comments]
|
||||||
|
|
||||||
return comments[:26]
|
|
||||||
|
|
||||||
@app.get("/comments")
|
@app.get("/comments")
|
||||||
@auth_desired
|
@auth_desired
|
||||||
|
|
|
@ -111,6 +111,10 @@ def post_id(pid, anything=None, v=None):
|
||||||
blocking.c.id,
|
blocking.c.id,
|
||||||
blocked.c.id,
|
blocked.c.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not (v and v.shadowbanned) and not (v and v.admin_level == 6):
|
||||||
|
comments = comments.join(Comment.author).filter(User.shadowbanned == False)
|
||||||
|
|
||||||
if v.admin_level >=4:
|
if v.admin_level >=4:
|
||||||
comments=comments.options(joinedload(Comment.oauth_app))
|
comments=comments.options(joinedload(Comment.oauth_app))
|
||||||
|
|
||||||
|
@ -149,7 +153,6 @@ def post_id(pid, anything=None, v=None):
|
||||||
output = []
|
output = []
|
||||||
for c in comments:
|
for c in comments:
|
||||||
comment = c[0]
|
comment = c[0]
|
||||||
if comment.author and comment.author.shadowbanned and not (v and v.id == comment.author_id): continue
|
|
||||||
comment.voted = c[1] or 0
|
comment.voted = c[1] or 0
|
||||||
comment._is_blocking = c[2] or 0
|
comment._is_blocking = c[2] or 0
|
||||||
comment._is_blocked = c[3] or 0
|
comment._is_blocked = c[3] or 0
|
||||||
|
@ -180,23 +183,23 @@ def post_id(pid, anything=None, v=None):
|
||||||
else:
|
else:
|
||||||
abort(422)
|
abort(422)
|
||||||
|
|
||||||
if random.random() < 0.02:
|
# if random.random() < 0.02:
|
||||||
for comment in comments:
|
# for comment in comments:
|
||||||
if comment.author and comment.author.shadowbanned:
|
# if comment.author and comment.author.shadowbanned:
|
||||||
rand = random.randint(5,20)
|
# rand = random.randint(5,20)
|
||||||
if comment.score > rand: continue
|
# if comment.score > rand: continue
|
||||||
rand = random.randint(500,1400)
|
# rand = random.randint(500,1400)
|
||||||
vote = CommentVote(user_id=rand,
|
# vote = CommentVote(user_id=rand,
|
||||||
vote_type=random.choice([-1, 1, 1, 1, 1]),
|
# vote_type=random.choice([-1, 1, 1, 1, 1]),
|
||||||
comment_id=comment.id)
|
# comment_id=comment.id)
|
||||||
g.db.add(vote)
|
# g.db.add(vote)
|
||||||
try: g.db.flush()
|
# try: g.db.flush()
|
||||||
except: g.db.rollback()
|
# except: g.db.rollback()
|
||||||
comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count()
|
# comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||||
comment.downvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=-1).count()
|
# comment.downvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=-1).count()
|
||||||
g.db.add(comment)
|
# g.db.add(comment)
|
||||||
|
|
||||||
post.preloaded_comments = [x for x in comments if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)]
|
post.preloaded_comments = comments
|
||||||
|
|
||||||
if not v or v.highlightcomments:
|
if not v or v.highlightcomments:
|
||||||
last_view_utc = session.get(str(post.id))
|
last_view_utc = session.get(str(post.id))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue