diff --git a/files/classes/comment.py b/files/classes/comment.py index 3aeda07a0..fbe536bc9 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -72,10 +72,14 @@ class Comment(Base): def top_comment(self): return g.db.query(Comment).filter_by(id=self.top_comment_id).one_or_none() - @property @lazy - def flags(self): - return g.db.query(CommentFlag).filter_by(comment_id=self.id).order_by(CommentFlag.created_utc) + def flags(self, v): + flags = g.db.query(CommentFlag).filter_by(comment_id=self.id).order_by(CommentFlag.created_utc).all() + if not (v and (v.shadowbanned or v.admin_level > 2)): + for flag in flags: + if flag.user.shadowbanned: + flags.remove(flag) + return flags @lazy def poll_voted(self, v): @@ -256,7 +260,7 @@ class Comment(Base): @lazy def json_raw(self): flags = {} - for f in self.flags: flags[f.user.username] = f.reason + for f in self.flags(None): flags[f.user.username] = f.reason data= { 'id': self.id, @@ -434,10 +438,9 @@ class Comment(Base): @lazy def is_op(self): return self.author_id==self.post.author_id - @property @lazy - def active_flags(self): return self.flags.count() - + def active_flags(self, v): return len(self.flags(v)) + @lazy def wordle_html(self, v): if not self.wordle_result: return '' diff --git a/files/classes/submission.py b/files/classes/submission.py index 5b17deb43..bff89c6e0 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -76,11 +76,15 @@ class Submission(Base): if self.downvotes > 5 and 0.25 < self.upvotes / self.downvotes < 4: return True return False - @property @lazy - def flags(self): - return g.db.query(Flag).filter_by(post_id=self.id).order_by(Flag.created_utc) - + def flags(self, v): + flags = g.db.query(Flag).filter_by(post_id=self.id).order_by(Flag.created_utc).all() + if not (v and (v.shadowbanned or v.admin_level > 2)): + for flag in flags: + if flag.user.shadowbanned: + flags.remove(flag) + return flags + @property @lazy def options(self): @@ -261,7 +265,7 @@ class Submission(Base): @lazy def json_raw(self): flags = {} - for f in self.flags: flags[f.user.username] = f.reason + for f in self.flags(None): flags[f.user.username] = f.reason data = {'author_name': self.author_name if self.author else '', 'permalink': self.permalink, @@ -477,6 +481,5 @@ class Submission(Base): if self.url: return self.url.lower().endswith('.webp') or self.url.lower().endswith('.jpg') or self.url.lower().endswith('.png') or self.url.lower().endswith('.gif') or self.url.lower().endswith('.jpeg') or self.url.lower().endswith('?maxwidth=9999') or self.url.lower().endswith('&fidelity=high') else: return False - @property @lazy - def active_flags(self): return self.flags.count() \ No newline at end of file + def active_flags(self, v): return len(self.flags(v)) \ No newline at end of file diff --git a/files/classes/user.py b/files/classes/user.py index ca096d144..a2d5397ef 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -422,7 +422,12 @@ class User(Base): @property @lazy def notifications_count(self): - return g.db.query(Notification.user_id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0).count() + notifs = g.db.query(Notification.user_id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0) + + if not self.shadowbanned and self.admin_level < 3: + notifs = notifs.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None) + + return notifs.count() @property @lazy @@ -516,8 +521,8 @@ class User(Base): 'bannerurl': self.banner_url, 'bio_html': self.bio_html_eager, 'coins': self.coins, - 'post_count': 0 if self.shadowbanned and not (v and (v.shadowbanned or v.admin_level)) else self.post_count, - 'comment_count': 0 if self.shadowbanned and not (v and (v.shadowbanned or v.admin_level)) else self.comment_count, + 'post_count': 0 if self.shadowbanned and not (v and (v.shadowbanned or v.admin_level > 2)) else self.post_count, + 'comment_count': 0 if self.shadowbanned and not (v and (v.shadowbanned or v.admin_level > 2)) else self.comment_count, 'badges': [x.path for x in self.badges], } diff --git a/files/helpers/get.py b/files/helpers/get.py index 7705adadf..8c411d975 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -231,7 +231,7 @@ def get_comments(cids, v=None, load_parent=False): blocked.c.target_id, ).filter(Comment.id.in_(cids)) - if not (v and (v.shadowbanned or v.admin_level > 1)): + if not (v and (v.shadowbanned or v.admin_level > 2)): comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None) comments = comments.join( diff --git a/files/routes/comments.py b/files/routes/comments.py index 551562187..b966de0d9 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -125,7 +125,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): blocked.c.target_id, ) - if not (v and v.shadowbanned) and not (v and v.admin_level > 1): + 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( diff --git a/files/routes/front.py b/files/routes/front.py index 094c3a7de..c703b10e7 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -49,7 +49,11 @@ def notifications(v): next_exists = (len(comments) > 25) listing = comments[:25] elif messages: - comments = g.db.query(Comment).filter(Comment.sentto != None, or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, Comment.level == 1).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all() + if v and (v.shadowbanned or v.admin_level > 2): + comments = g.db.query(Comment).filter(Comment.sentto != None, or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, Comment.level == 1).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all() + else: + comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.sentto != None, or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, Comment.level == 1).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all() + next_exists = (len(comments) > 25) listing = comments[:25] elif posts: @@ -112,7 +116,7 @@ def notifications(v): Comment.body_html.notlike('
New site mention: 350: return {"error": "Too long."}
+ if not reason.startswith('!'):
+ existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
+ if existing: return "", 409
- if reason.startswith('!') and v.admin_level > 1:
- post.flair = reason[1:]
- g.db.add(post)
- ma=ModAction(
- kind="flair_post",
- user_id=v.id,
- target_submission_id=post.id,
- _note=f'"{post.flair}"'
- )
- g.db.add(ma)
- else:
- flag = Flag(post_id=post.id, user_id=v.id, reason=reason)
- g.db.add(flag)
+ reason = filter_emojis_only(reason)
- g.db.commit()
+ if len(reason) > 350: return {"error": "Too long."}
+
+ if reason.startswith('!') and v.admin_level > 1:
+ post.flair = reason[1:]
+ g.db.add(post)
+ ma=ModAction(
+ kind="flair_post",
+ user_id=v.id,
+ target_submission_id=post.id,
+ _note=f'"{post.flair}"'
+ )
+ g.db.add(ma)
+ else:
+ flag = Flag(post_id=post.id, user_id=v.id, reason=reason)
+ g.db.add(flag)
+
+ g.db.commit()
return {"message": "Post reported!"}
@@ -49,19 +54,25 @@ def api_flag_comment(cid, v):
comment = get_comment(cid)
- if not v.shadowbanned:
- existing = g.db.query(CommentFlag.comment_id).filter_by( user_id=v.id, comment_id=comment.id).one_or_none()
- if existing: return "", 409
+ existing = g.db.query(CommentFlag.comment_id).filter_by( user_id=v.id, comment_id=comment.id).one_or_none()
+ if existing: return "", 409
- reason = request.values.get("reason", "").strip()[:100]
- reason = filter_emojis_only(reason)
+ reason = request.values.get("reason", "").strip()
- if len(reason) > 350: return {"error": "Too long."}
+ if blackjack and blackjack in reason.lower():
+ v.shadowbanned = 'AutoJanny'
+ send_repeatable_notification(CARP_ID, f"reports on {comment.permalink}")
- flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason)
+ reason = reason[:100]
- g.db.add(flag)
- g.db.commit()
+ reason = filter_emojis_only(reason)
+
+ if len(reason) > 350: return {"error": "Too long."}
+
+ flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason)
+
+ g.db.add(flag)
+ g.db.commit()
return {"message": "Comment reported!"}
diff --git a/files/routes/users.py b/files/routes/users.py
index d205d97a0..caf8bb508 100644
--- a/files/routes/users.py
+++ b/files/routes/users.py
@@ -600,8 +600,6 @@ def message2(v, username):
if v.admin_level <= 1 and hasattr(user, 'is_blocked') and user.is_blocked:
return {"error": "This user is blocking you."}, 403
- if v.shadowbanned and user.admin_level < 2: return {"message": "Message sent!"}
-
message = request.values.get("message", "").strip()[:10000].strip()
if not message: return {"error": "Message is empty!"}
@@ -629,11 +627,21 @@ def message2(v, username):
g.db.flush()
+ if blackjack and blackjack in c.body_html.lower():
+ v.shadowbanned = 'AutoJanny'
+ g.db.add(v)
+ notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=CARP_ID).one_or_none()
+ if not notif:
+ notif = Notification(comment_id=c.id, user_id=CARP_ID)
+ g.db.add(notif)
+ g.db.flush()
+
c.top_comment_id = c.id
-
- notif = Notification(comment_id=c.id, user_id=user.id)
- g.db.add(notif)
+ notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=user.id).one_or_none()
+ if not notif:
+ notif = Notification(comment_id=c.id, user_id=user.id)
+ g.db.add(notif)
g.db.commit()
@@ -688,7 +696,7 @@ def messagereply(v):
else: return {"error": "Image/Video files only"}, 400
- new_comment = Comment(author_id=v.id,
+ c = Comment(author_id=v.id,
parent_submission=None,
parent_comment_id=id,
top_comment_id=parent.top_comment_id,
@@ -696,12 +704,23 @@ def messagereply(v):
sentto=user_id,
body_html=body_html,
)
- g.db.add(new_comment)
+ g.db.add(c)
g.db.flush()
+ if blackjack and blackjack in c.body_html.lower():
+ v.shadowbanned = 'AutoJanny'
+ g.db.add(v)
+ notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=CARP_ID).one_or_none()
+ if not notif:
+ notif = Notification(comment_id=c.id, user_id=CARP_ID)
+ g.db.add(notif)
+ g.db.flush()
+
if user_id and user_id != v.id and user_id != 2:
- notif = Notification(comment_id=new_comment.id, user_id=user_id)
- g.db.add(notif)
+ notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=user_id).one_or_none()
+ if not notif:
+ notif = Notification(comment_id=c.id, user_id=user_id)
+ g.db.add(notif)
if PUSHER_ID != 'blahblahblah':
if len(message) > 500: notifbody = message[:500] + '...'
@@ -731,14 +750,14 @@ def messagereply(v):
)
- if new_comment.top_comment.sentto == 2:
+ if c.top_comment.sentto == 2:
admins = g.db.query(User).filter(User.admin_level > 2, User.id != v.id).all()
for admin in admins:
- notif = Notification(comment_id=new_comment.id, user_id=admin.id)
+ notif = Notification(comment_id=c.id, user_id=admin.id)
g.db.add(notif)
g.db.commit()
- return {"comment": render_template("comments.html", v=v, comments=[new_comment], ajax=True)}
+ return {"comment": render_template("comments.html", v=v, comments=[c], ajax=True)}
@app.get("/2faqr/
- {% for f in c.flags %}
+ {% for f in c.flags(v) %}
diff --git a/files/templates/submission.html b/files/templates/submission.html
index f9aff0837..e74d4d6e1 100644
--- a/files/templates/submission.html
+++ b/files/templates/submission.html
@@ -636,7 +636,7 @@
{% if p.is_bot %} {% endif %}
{% if p.over_18 %}+18{% endif %}
{% if p.private %}Draft{% endif %}
- {% if p.active_flags %}{{p.active_flags}} Reports{% endif %}
+ {% if p.active_flags(v) %}{{p.active_flags(v)}} Reports{% endif %}
{% if not p.author %}
{{p.print()}}
@@ -661,12 +661,12 @@
{% endif %}
{{p.views}} thread views
- {% for f in p.flags %}
+ {% for f in p.flags(v) %}
diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html
index 90789af04..613df8e96 100644
--- a/files/templates/submission_listing.html
+++ b/files/templates/submission_listing.html
@@ -62,12 +62,12 @@
{% set voted=-2 %}
{% endif %}
-{% if p.active_flags %}
+{% if p.active_flags(v) %}
- {% for f in p.flags %}
+ {% for f in p.flags(v) %}
@@ -179,7 +179,7 @@
{% if p.is_blocking %}{% endif %}
{% if p.is_blocked %}{% endif %}
{% if p.private %}Draft{% endif %}
- {% if p.active_flags %}{{p.active_flags}} Reports{% endif %}
+ {% if p.active_flags(v) %}{{p.active_flags(v)}} Reports{% endif %}
{% if not p.author %}
{{p.print()}}