= NOTIF_MODACTION_JL_MIN, User.id != by_id).all()
+ for admin in send_to:
+ notif = Notification(comment_id=new_comment.id, user_id=admin.id)
+ g.db.add(notif)
diff --git a/files/helpers/const.py b/files/helpers/const.py
index a7e2a19b9..3423d2313 100644
--- a/files/helpers/const.py
+++ b/files/helpers/const.py
@@ -809,6 +809,9 @@ FACTCHECK_REPLIES = ('Factcheck: This claim has been co
if SITE_NAME == 'rDrama': patron = 'Paypig'
else: patron = 'Patron'
+NOTIF_MODACTION_PREFIX = '[Modaction] '
+NOTIF_MODACTION_JL_MIN = 2
+
REDDIT_NOTIFS_SITE = []
REDDIT_NOTIFS_USERS = {}
REDDIT_NOTIFS_JL_MIN = 1
diff --git a/files/routes/admin.py b/files/routes/admin.py
index 2c9bda416..b3d15b708 100644
--- a/files/routes/admin.py
+++ b/files/routes/admin.py
@@ -527,25 +527,7 @@ def change_settings(v, setting):
if site_settings[setting]: word = 'enable'
else: word = 'disable'
- body = f"@{v.username} has {word}d `{setting}` in the [admin dashboard](/admin)!"
-
- body_html = sanitize(body)
-
- new_comment = Comment(author_id=NOTIFICATIONS_ID,
- parent_submission=None,
- level=1,
- body_html=body_html,
- sentto=2,
- distinguish_level=6
- )
- g.db.add(new_comment)
- g.db.flush()
-
- new_comment.top_comment_id = new_comment.id
-
- for admin in g.db.query(User).filter(User.admin_level > 2, User.id != v.id).all():
- notif = Notification(comment_id=new_comment.id, user_id=admin.id)
- g.db.add(notif)
+ notify_mod_action(v.id, f"@{v.username} has {word}d `{setting}` in the [admin dashboard](/admin)!")
ma = ModAction(
kind=f"{word}_{setting}",
@@ -1018,29 +1000,7 @@ def shadowban(user_id, v):
g.db.add(ma)
cache.delete_memoized(frontlist)
-
- body = f"@{v.username} has shadowbanned @{user.username}"
-
- body_html = sanitize(body)
-
-
- new_comment = Comment(author_id=NOTIFICATIONS_ID,
- parent_submission=None,
- level=1,
- body_html=body_html,
- distinguish_level=6
- )
- g.db.add(new_comment)
- g.db.flush()
-
- new_comment.top_comment_id = new_comment.id
-
- for admin in g.db.query(User).filter(User.admin_level > 2, User.id != v.id).all():
- notif = Notification(comment_id=new_comment.id, user_id=admin.id)
- g.db.add(notif)
-
-
-
+ notify_mod_action(v.id, f"@{v.username} has shadowbanned @{user.username}")
g.db.commit()
return {"message": "User shadowbanned!"}
@@ -1176,28 +1136,7 @@ def ban_user(user_id, v):
g.db.add(comment)
except: pass
-
- body = f"@{v.username} has banned @{user.username} ({note})"
-
- body_html = sanitize(body)
-
-
- new_comment = Comment(author_id=NOTIFICATIONS_ID,
- parent_submission=None,
- level=1,
- body_html=body_html,
- distinguish_level=6
- )
- g.db.add(new_comment)
- g.db.flush()
-
- new_comment.top_comment_id = new_comment.id
-
- for admin in g.db.query(User).filter(User.admin_level > 2, User.id != v.id).all():
- notif = Notification(comment_id=new_comment.id, user_id=admin.id)
- g.db.add(notif)
-
-
+ notify_mod_action(v.id, f"@{v.username} has banned @{user.username} ({note})")
g.db.commit()
if 'redir' in request.values: return redirect(user.url)
@@ -1273,23 +1212,10 @@ def ban_post(post_id, v):
g.db.add(v)
if v.id != post.author_id:
- body = f"@{v.username} has removed [{post.title}]({post.shortlink})"
- body_html = sanitize(body)
- new_comment = Comment(author_id=NOTIFICATIONS_ID,
- parent_submission=None,
- level=1,
- body_html=body_html,
- distinguish_level=6
- )
- g.db.add(new_comment)
- g.db.flush()
- new_comment.top_comment_id = new_comment.id
- for admin in g.db.query(User).filter(User.admin_level > 2, User.id != v.id).all():
- notif = Notification(comment_id=new_comment.id, user_id=admin.id)
- g.db.add(notif)
-
- requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, json={'files': [f"{SITE_FULL}/logged_out/"]}, timeout=5)
+ notify_mod_action(v.id, f"@{v.username} has removed [{post.title}]({post.shortlink})")
+ requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache',
+ headers=CF_HEADERS, json={'files': [f"{SITE_FULL}/logged_out/"]}, timeout=5)
g.db.commit()
return {"message": "Post removed!"}
@@ -1492,20 +1418,7 @@ def api_ban_comment(c_id, v):
g.db.add(ma)
if v.id != comment.author_id:
- body = f"@{v.username} has removed [comment]({comment.shortlink})"
- body_html = sanitize(body)
- new_comment = Comment(author_id=NOTIFICATIONS_ID,
- parent_submission=None,
- level=1,
- body_html=body_html,
- distinguish_level=6
- )
- g.db.add(new_comment)
- g.db.flush()
- new_comment.top_comment_id = new_comment.id
- for admin in g.db.query(User).filter(User.admin_level > 2, User.id != v.id).all():
- notif = Notification(comment_id=new_comment.id, user_id=admin.id)
- g.db.add(notif)
+ notify_mod_action(v.id, f"@{v.username} has removed [comment]({comment.shortlink})")
g.db.commit()
return {"message": "Comment removed!"}
diff --git a/files/routes/front.py b/files/routes/front.py
index 091aa2cbc..7337302e6 100644
--- a/files/routes/front.py
+++ b/files/routes/front.py
@@ -44,9 +44,10 @@ def notifications(v):
messages = request.values.get('messages')
modmail = request.values.get('modmail')
+ modactions = request.values.get('modactions')
posts = request.values.get('posts')
reddit = request.values.get('reddit')
- if modmail and v.admin_level > 1:
+ if modmail and v.admin_level >= 2:
comments = g.db.query(Comment).filter(Comment.sentto==2).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all()
next_exists = (len(comments) > 25)
listing = comments[:25]
@@ -73,7 +74,25 @@ def notifications(v):
if n.created_utc > 1620391248: c.notif_utc = n.created_utc
listing.append(c)
- g.db.commit()
+ next_exists = (len(notifications) > len(listing))
+ elif modactions:
+ notifications = g.db.query(Notification, Comment) \
+ .join(Comment, Notification.comment_id == Comment.id) \
+ .filter(Notification.user_id == v.id,
+ Comment.body_html.like(f'%{NOTIF_MODACTION_PREFIX}%'),
+ Comment.parent_submission == None, Comment.author_id == NOTIFICATIONS_ID) \
+ .order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all()
+ listing = []
+
+ for index, x in enumerate(notifications[:100]):
+ n, c = x
+ if n.read and index > 24: break
+ elif not n.read:
+ n.read = True
+ c.unread = True
+ g.db.add(n)
+ if n.created_utc > 1620391248: c.notif_utc = n.created_utc
+ listing.append(c)
next_exists = (len(notifications) > len(listing))
elif reddit:
@@ -91,8 +110,6 @@ def notifications(v):
if n.created_utc > 1620391248: c.notif_utc = n.created_utc
listing.append(c)
- g.db.commit()
-
next_exists = (len(notifications) > len(listing))
else:
comments = g.db.query(Comment, Notification).join(Notification, Notification.comment_id == Comment.id).filter(
@@ -100,7 +117,8 @@ def notifications(v):
Comment.is_banned == False,
Comment.deleted_utc == 0,
Comment.author_id != AUTOJANNY_ID,
- Comment.body_html.notlike('%
New site mention: {NOTIF_MODACTION_PREFIX}%')
).order_by(Notification.created_utc.desc())
if not (v and (v.shadowbanned or v.admin_level > 2)):
@@ -154,7 +172,8 @@ def notifications(v):
next_exists=next_exists,
page=page,
standalone=True,
- render_replies=True
+ render_replies=True,
+ NOTIF_MODACTION_JL_MIN=NOTIF_MODACTION_JL_MIN,
)
diff --git a/files/templates/notifications.html b/files/templates/notifications.html
index e562f2775..09c456eab 100644
--- a/files/templates/notifications.html
+++ b/files/templates/notifications.html
@@ -14,7 +14,7 @@