diff --git a/docker-compose.yml b/docker-compose.yml index ac99b2d20..b53fb74b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,7 @@ services: postgres: image: postgres:12.3 - # command: ["postgres", "-c", "log_statement=all"] + command: ["postgres", "-c", "log_statement=all"] # uncomment this if u wanna output all SQL queries to the console volumes: - "./schema.sql:/docker-entrypoint-initdb.d/00-schema.sql" diff --git a/files/classes/comment.py b/files/classes/comment.py index 4b3ef3278..98f056acd 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -107,13 +107,6 @@ class Comment(Base): flags.remove(flag) return flags - @lazy - def poll_voted(self, v): - if v: - vote = g.db.query(CommentVote.vote_type).filter_by(user_id=v.id, comment_id=self.id).one_or_none() - if vote: return vote[0] - return None - @property @lazy def options(self): @@ -128,13 +121,13 @@ class Comment(Base): def total_poll_voted(self, v): if v: for option in self.options: - if option.poll_voted(v): return True + if option.voted: return True return False @lazy def total_choice_voted(self, v): if v: - return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all() + return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).count() return False @property @@ -247,7 +240,7 @@ class Comment(Base): if not self.parent_submission: return [x for x in self.child_comments.order_by(Comment.id) if not x.author.shadowbanned] - comments = self.child_comments.filter(Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID))) + comments = self.child_comments.filter(Comment.author_id.notin_(poll_bots)) comments = sort_comments(sort, comments) return [x for x in comments if not x.author.shadowbanned] @@ -258,7 +251,7 @@ class Comment(Base): if not self.parent_submission: return self.child_comments.order_by(Comment.id).all() - comments = self.child_comments.filter(Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID))) + comments = self.child_comments.filter(Comment.author_id.notin_(poll_bots)) return sort_comments(sort, comments).all() @@ -415,7 +408,7 @@ class Comment(Base): for c in self.options: body += f'
' diff --git a/files/classes/submission.py b/files/classes/submission.py index c6174196e..ebb3dedba 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -122,13 +122,13 @@ class Submission(Base): def total_poll_voted(self, v): if v: for option in self.options: - if option.poll_voted(v): return True + if option.voted: return True return False @lazy def total_choice_voted(self, v): if v and self.choices: - return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all() + return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).count() return False @lazy @@ -136,7 +136,7 @@ class Submission(Base): if "closed" in self.body.lower(): return True if v: for option in self.bet_options: - if option.poll_voted(v): return True + if option.voted: return True return False @property @@ -387,7 +387,7 @@ class Submission(Base): return url @lazy - def realbody(self, v): + def realbody(self, v, show_polls=False): if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"

{CC} ONLY

" body = self.body_html or "" @@ -408,43 +408,43 @@ class Submission(Base): g.db.add(self) g.db.commit() - for c in self.options: - body += f'
' + if show_polls: + for c in self.options: + body += f'
' - if self.choices: - curr = self.total_choice_voted(v) - if curr: curr = " value=" + str(curr[0].comment_id) - else: curr = '' - body += f'' + if self.choices: + curr = self.total_choice_voted(v) + if curr: curr = " value=" + str(curr[0].comment_id) + else: curr = '' + body += f'' - for c in self.choices: - body += f'''
' + for c in self.choices: + body += f'''
' - for c in self.bet_options: - body += f'''
200) or self.total_bet_voted(v) or not v.can_gamble: body += " disabled " - body += f'''>" - if v and v.admin_level > 2: - body += f'''''' - body += "
" + for c in self.bet_options: + body += f'''
200) or self.total_bet_voted(v) or not v.can_gamble: body += " disabled " + body += f'''>" + if v and v.admin_level > 2: + body += f'''''' + body += "
" - - if self.author.sig_html and (self.author_id == MOOSE_ID or (not self.ghost and not (v and v.sigs_disabled))): - body += f"
{self.author.sig_html}" + if self.author.sig_html and (self.author_id == MOOSE_ID or (not self.ghost and not (v and v.sigs_disabled))): + body += f"
{self.author.sig_html}" return body diff --git a/files/classes/user.py b/files/classes/user.py index 67a5b3c01..991420104 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -474,6 +474,7 @@ class User(Base): @property @lazy def modaction_notifications_count(self): + if not self.admin_level: return 0 return g.db.query(Notification).join(Comment).filter( Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0, @@ -483,6 +484,7 @@ class User(Base): @property @lazy def reddit_notifications_count(self): + if not self.can_view_offsitementions: return 0 return g.db.query(Notification).join(Comment).filter( Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0, @@ -697,6 +699,9 @@ class User(Base): def saved_idlist(self, page=1): saved = [x[0] for x in g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).all()] + + if not saved: return [] + posts = g.db.query(Submission.id).filter(Submission.id.in_(saved), Submission.is_banned == False, Submission.deleted_utc == 0) if self.admin_level < 2: @@ -708,6 +713,9 @@ class User(Base): def saved_comment_idlist(self, page=1): saved = [x[0] for x in g.db.query(CommentSaveRelationship.comment_id).filter_by(user_id=self.id).all()] + + if not saved: return [] + comments = g.db.query(Comment.id).filter(Comment.id.in_(saved), Comment.is_banned == False, Comment.deleted_utc == 0) if self.admin_level < 2: diff --git a/files/helpers/get.py b/files/helpers/get.py index f3504f8bf..7629880da 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -120,8 +120,8 @@ def get_post(i, v=None, graceful=False): else: abort(404) if v: - vt = g.db.query(Vote).filter_by( - user_id=v.id, submission_id=i).subquery() + vt = g.db.query(Vote.vote_type, Vote.submission_id).filter_by(user_id=v.id, submission_id=i).subquery() + blocking = v.blocking.subquery() post = g.db.query( @@ -166,7 +166,7 @@ def get_posts(pids, v=None): return [] if v: - vt = g.db.query(Vote).filter( + vt = g.db.query(Vote.vote_type, Vote.submission_id).filter( Vote.submission_id.in_(pids), Vote.user_id==v.id ).subquery() @@ -228,8 +228,7 @@ def get_comment(i, v=None, graceful=False): ) ).first() - vts = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id) - vt = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).one_or_none() + vt = g.db.query(CommentVote.vote_type).filter_by(user_id=v.id, comment_id=comment.id).one_or_none() comment.is_blocking = block and block.user_id == v.id comment.is_blocked = block and block.target_id == v.id comment.voted = vt.vote_type if vt else 0 @@ -242,7 +241,7 @@ def get_comments(cids, v=None, load_parent=False): if not cids: return [] if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + votes = g.db.query(CommentVote.vote_type, CommentVote.comment_id).filter_by(user_id=v.id).subquery() blocking = v.blocking.subquery() diff --git a/files/routes/comments.py b/files/routes/comments.py index 25e450c79..efdf4e3e9 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -118,7 +118,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): sort=request.values.get("sort", defaultsortingcomments) if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + votes = g.db.query(CommentVote.vote_type, CommentVote.comment_id).filter_by(user_id=v.id).subquery() blocking = v.blocking.subquery() @@ -135,8 +135,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None) comments=comments.filter( - Comment.parent_submission == post.id, - Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)) + Comment.top_comment_id == c.top_comment_id ).join( votes, votes.c.comment_id == Comment.id, diff --git a/files/routes/posts.py b/files/routes/posts.py index b24f2fe7a..6bc423178 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -149,7 +149,7 @@ def post_id(pid, anything=None, v=None, sub=None): if post.club and not (v and (v.paid_dues or v.id == post.author_id)): abort(403) if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + votes = g.db.query(CommentVote.vote_type, CommentVote.comment_id).filter_by(user_id=v.id).subquery() blocking = v.blocking.subquery() @@ -165,7 +165,7 @@ def post_id(pid, anything=None, v=None, sub=None): if not (v and v.shadowbanned) and not (v and v.admin_level >= 2): comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None) - comments=comments.filter(Comment.parent_submission == post.id, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID))).join( + comments=comments.filter(Comment.parent_submission == post.id).join( votes, votes.c.comment_id == Comment.id, isouter=True @@ -189,7 +189,7 @@ def post_id(pid, anything=None, v=None, sub=None): pinned = [c[0] for c in comments.filter(Comment.stickied != None).all()] - comments = comments.filter(Comment.level == 1, Comment.stickied == None) + comments = comments.filter(Comment.level == 1, Comment.stickied == None, Comment.author_id.notin_(poll_bots)) comments = sort_comments(sort, comments) @@ -199,7 +199,7 @@ def post_id(pid, anything=None, v=None, sub=None): else: pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.stickied != None).all() - comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == post.id, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), Comment.level == 1, Comment.stickied == None) + comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == post.id, Comment.author_id.notin_(poll_bots), Comment.level == 1, Comment.stickied == None) comments = sort_comments(sort, comments) @@ -262,7 +262,7 @@ def viewmore(v, pid, sort, offset): except: abort(400) if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + votes = g.db.query(CommentVote.vote_type, CommentVote.comment_id).filter_by(user_id=v.id).subquery() blocking = v.blocking.subquery() @@ -273,7 +273,7 @@ def viewmore(v, pid, sort, offset): votes.c.vote_type, blocking.c.target_id, blocked.c.target_id, - ).filter(Comment.parent_submission == pid, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), Comment.stickied == None, Comment.id.notin_(ids)) + ).filter(Comment.parent_submission == pid, Comment.stickied == None, Comment.id.notin_(ids)) if not (v and v.shadowbanned) and not (v and v.admin_level >= 2): comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None) @@ -300,7 +300,7 @@ def viewmore(v, pid, sort, offset): comment.is_blocked = c[3] or 0 output.append(comment) - comments = comments.filter(Comment.level == 1) + comments = comments.filter(Comment.level == 1, Comment.author_id.notin_(poll_bots)) comments = sort_comments(sort, comments) @@ -308,7 +308,7 @@ def viewmore(v, pid, sort, offset): second = [c[0] for c in comments.filter(or_(Comment.slots_result != None, Comment.blackjack_result != None, Comment.wordle_result != None), func.length(Comment.body_html) <= 100).all()] comments = first + second else: - comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == pid, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), Comment.level == 1, Comment.stickied == None, Comment.id.notin_(ids)) + comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == pid, Comment.author_id.notin_(poll_bots), Comment.level == 1, Comment.stickied == None, Comment.id.notin_(ids)) comments = sort_comments(sort, comments) @@ -349,7 +349,7 @@ def morecomments(v, cid): tcid = g.db.query(Comment.top_comment_id).filter_by(id=cid).one_or_none()[0] if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() + votes = g.db.query(CommentVote.vote_type, CommentVote.comment_id).filter_by(user_id=v.id).subquery() blocking = v.blocking.subquery() diff --git a/files/templates/comments.html b/files/templates/comments.html index 3feb22d82..aa19b2b9a 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -877,7 +877,7 @@ lastCount = comments['{{p.id}}'] if (lastCount) { - {% for c in p.comments %} + {% for c in p.replies %} {% if not (v and v.id==c.author_id) and not c.voted %} if ({{c.created_utc*1000}} > lastCount.t) try {document.getElementById("comment-{{c.id}}-only").classList.add('unread')} @@ -908,7 +908,7 @@ lastCount = comments['{{p.id}}'] if (lastCount) { - {% for c in p.comments %} + {% for c in p.replies %} {% if not (v and v.id==c.author_id) and not c.voted %} if ({{c.created_utc*1000}} > lastCount.t) try {document.getElementById("comment-{{c.id}}-only").classList.add('unread')} diff --git a/files/templates/submission.html b/files/templates/submission.html index 7d4ebdef4..1d71353a4 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -733,10 +733,6 @@ {% if p.private %}Draft{% endif %} {% if p.active_flags(v) %}{{p.active_flags(v)}} Report{{ help.plural(p.active_flags(v)) }}{% endif %} - {% if not p.author %} - {{p.print()}} - {% endif %} - {% if p.ghost %} 👻 {% else %} @@ -795,7 +791,7 @@ {% if p.realurl(v) %} {% if not p.embed_url and not p.is_image and not p.is_video and not p.is_audio %} -
+
{{p.domain|truncate(30, True)}}
@@ -845,7 +841,7 @@

 							{% endif %}
-							{{p.realbody(v) | safe}}
+							{{p.realbody(v, show_polls=True) | safe}}
 
 							{% if p.is_banned and p.ban_reason %}
 								
removed by @{{p.ban_reason}}
@@ -1127,7 +1123,7 @@ lastCount = comments['{{p.id}}'] if (lastCount) { - {% for c in p.comments %} + {% for c in p.replies %} {% if not (v and v.id==c.author_id) and not c.voted %} if ({{c.created_utc*1000}} > lastCount.t) try {document.getElementById("comment-{{c.id}}-only").classList.add('unread')} diff --git a/files/templates/submission_banned.html b/files/templates/submission_banned.html index 18bd934f2..60c7a31cd 100644 --- a/files/templates/submission_banned.html +++ b/files/templates/submission_banned.html @@ -94,7 +94,7 @@ lastCount = comments['{{p.id}}'] if (lastCount) { - {% for c in p.comments %} + {% for c in p.replies %} {% if not (v and v.id==c.author_id) and not c.voted %} if ({{c.created_utc*1000}} > lastCount.t) try {document.getElementById("comment-{{c.id}}-only").classList.add('unread')}