forked from rDrama/rDrama
Separate modaction notifs from inbox.
parent
8709ca816d
commit
4db48a6ec9
|
@ -452,22 +452,44 @@ class User(Base):
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def post_notifications_count(self):
|
def post_notifications_count(self):
|
||||||
return g.db.query(Notification).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ID).count()
|
return g.db.query(Notification).join(Comment).filter(
|
||||||
|
Notification.user_id == self.id, Notification.read == False,
|
||||||
|
Comment.author_id == AUTOJANNY_ID).count()
|
||||||
|
|
||||||
|
@property
|
||||||
|
@lazy
|
||||||
|
def modaction_notifications_count(self):
|
||||||
|
return g.db.query(Notification).join(Comment).filter(
|
||||||
|
Notification.user_id == self.id, Notification.read == False,
|
||||||
|
Comment.is_banned == False, Comment.deleted_utc == 0,
|
||||||
|
Comment.body_html.like(f'%<p>{NOTIF_MODACTION_PREFIX}%'),
|
||||||
|
Comment.parent_submission == None, Comment.author_id == NOTIFICATIONS_ID).count()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def reddit_notifications_count(self):
|
def reddit_notifications_count(self):
|
||||||
return g.db.query(Notification).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0, Comment.body_html.like('%<p>New site mention: <a href="https://old.reddit.com/r/%'), Comment.parent_submission == None, Comment.author_id == NOTIFICATIONS_ID).count()
|
return g.db.query(Notification).join(Comment).filter(
|
||||||
|
Notification.user_id == self.id, Notification.read == False,
|
||||||
|
Comment.is_banned == False, Comment.deleted_utc == 0,
|
||||||
|
Comment.body_html.like('%<p>New site mention: <a href="https://old.reddit.com/r/%'),
|
||||||
|
Comment.parent_submission == None, Comment.author_id == NOTIFICATIONS_ID).count()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def normal_count(self):
|
def normal_count(self):
|
||||||
return self.notifications_count - self.post_notifications_count - self.reddit_notifications_count
|
return self.notifications_count \
|
||||||
|
- self.post_notifications_count \
|
||||||
|
- self.modaction_notifications_count \
|
||||||
|
- self.reddit_notifications_count
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def do_posts(self):
|
def do_posts(self):
|
||||||
return self.post_notifications_count and self.notifications_count-self.reddit_notifications_count == self.post_notifications_count
|
return self.post_notifications_count and \
|
||||||
|
self.post_notifications_count == (
|
||||||
|
self.notifications_count
|
||||||
|
- self.modaction_notifications_count
|
||||||
|
- self.reddit_notifications_count)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
|
|
|
@ -114,4 +114,22 @@ def NOTIFY_USERS(text, v):
|
||||||
user = get_user(i.group(2), graceful=True)
|
user = get_user(i.group(2), graceful=True)
|
||||||
if user and v.id != user.id and not v.any_block_exists(user): notify_users.add(user.id)
|
if user and v.id != user.id and not v.any_block_exists(user): notify_users.add(user.id)
|
||||||
|
|
||||||
return notify_users - bots
|
return notify_users - bots
|
||||||
|
|
||||||
|
def notify_mod_action(by_id, msg):
|
||||||
|
body_html = sanitize(NOTIF_MODACTION_PREFIX + msg)
|
||||||
|
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
|
||||||
|
|
||||||
|
send_to = g.db.query(User).filter(
|
||||||
|
User.admin_level >= 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)
|
||||||
|
|
|
@ -809,6 +809,9 @@ FACTCHECK_REPLIES = ('<b style="color:#6023f8">Factcheck: This claim has been co
|
||||||
if SITE_NAME == 'rDrama': patron = 'Paypig'
|
if SITE_NAME == 'rDrama': patron = 'Paypig'
|
||||||
else: patron = 'Patron'
|
else: patron = 'Patron'
|
||||||
|
|
||||||
|
NOTIF_MODACTION_PREFIX = '[Modaction] '
|
||||||
|
NOTIF_MODACTION_JL_MIN = 2
|
||||||
|
|
||||||
REDDIT_NOTIFS_SITE = []
|
REDDIT_NOTIFS_SITE = []
|
||||||
REDDIT_NOTIFS_USERS = {}
|
REDDIT_NOTIFS_USERS = {}
|
||||||
REDDIT_NOTIFS_JL_MIN = 1
|
REDDIT_NOTIFS_JL_MIN = 1
|
||||||
|
|
|
@ -527,25 +527,7 @@ def change_settings(v, setting):
|
||||||
if site_settings[setting]: word = 'enable'
|
if site_settings[setting]: word = 'enable'
|
||||||
else: word = 'disable'
|
else: word = 'disable'
|
||||||
|
|
||||||
body = f"@{v.username} has {word}d `{setting}` in the [admin dashboard](/admin)!"
|
notify_mod_action(v.id, 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)
|
|
||||||
|
|
||||||
ma = ModAction(
|
ma = ModAction(
|
||||||
kind=f"{word}_{setting}",
|
kind=f"{word}_{setting}",
|
||||||
|
@ -1018,29 +1000,7 @@ def shadowban(user_id, v):
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
cache.delete_memoized(frontlist)
|
cache.delete_memoized(frontlist)
|
||||||
|
notify_mod_action(v.id, f"@{v.username} has shadowbanned @{user.username}")
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return {"message": "User shadowbanned!"}
|
return {"message": "User shadowbanned!"}
|
||||||
|
|
||||||
|
@ -1176,28 +1136,7 @@ def ban_user(user_id, v):
|
||||||
g.db.add(comment)
|
g.db.add(comment)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
|
notify_mod_action(v.id, f"@{v.username} has banned @{user.username} ({note})")
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
if 'redir' in request.values: return redirect(user.url)
|
if 'redir' in request.values: return redirect(user.url)
|
||||||
|
@ -1273,23 +1212,10 @@ def ban_post(post_id, v):
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
|
||||||
if v.id != post.author_id:
|
if v.id != post.author_id:
|
||||||
body = f"@{v.username} has removed [{post.title}]({post.shortlink})"
|
notify_mod_action(v.id, 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)
|
|
||||||
|
|
||||||
|
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()
|
g.db.commit()
|
||||||
|
|
||||||
return {"message": "Post removed!"}
|
return {"message": "Post removed!"}
|
||||||
|
@ -1492,20 +1418,7 @@ def api_ban_comment(c_id, v):
|
||||||
g.db.add(ma)
|
g.db.add(ma)
|
||||||
|
|
||||||
if v.id != comment.author_id:
|
if v.id != comment.author_id:
|
||||||
body = f"@{v.username} has removed [comment]({comment.shortlink})"
|
notify_mod_action(v.id, 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)
|
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return {"message": "Comment removed!"}
|
return {"message": "Comment removed!"}
|
||||||
|
|
|
@ -44,9 +44,10 @@ def notifications(v):
|
||||||
|
|
||||||
messages = request.values.get('messages')
|
messages = request.values.get('messages')
|
||||||
modmail = request.values.get('modmail')
|
modmail = request.values.get('modmail')
|
||||||
|
modactions = request.values.get('modactions')
|
||||||
posts = request.values.get('posts')
|
posts = request.values.get('posts')
|
||||||
reddit = request.values.get('reddit')
|
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()
|
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)
|
next_exists = (len(comments) > 25)
|
||||||
listing = comments[:25]
|
listing = comments[:25]
|
||||||
|
@ -73,7 +74,25 @@ def notifications(v):
|
||||||
if n.created_utc > 1620391248: c.notif_utc = n.created_utc
|
if n.created_utc > 1620391248: c.notif_utc = n.created_utc
|
||||||
listing.append(c)
|
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'%<p>{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))
|
next_exists = (len(notifications) > len(listing))
|
||||||
elif reddit:
|
elif reddit:
|
||||||
|
@ -91,8 +110,6 @@ def notifications(v):
|
||||||
if n.created_utc > 1620391248: c.notif_utc = n.created_utc
|
if n.created_utc > 1620391248: c.notif_utc = n.created_utc
|
||||||
listing.append(c)
|
listing.append(c)
|
||||||
|
|
||||||
g.db.commit()
|
|
||||||
|
|
||||||
next_exists = (len(notifications) > len(listing))
|
next_exists = (len(notifications) > len(listing))
|
||||||
else:
|
else:
|
||||||
comments = g.db.query(Comment, Notification).join(Notification, Notification.comment_id == Comment.id).filter(
|
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.is_banned == False,
|
||||||
Comment.deleted_utc == 0,
|
Comment.deleted_utc == 0,
|
||||||
Comment.author_id != AUTOJANNY_ID,
|
Comment.author_id != AUTOJANNY_ID,
|
||||||
Comment.body_html.notlike('%<p>New site mention: <a href="https://old.reddit.com/r/%')
|
Comment.body_html.notlike('%<p>New site mention: <a href="https://old.reddit.com/r/%'),
|
||||||
|
Comment.body_html.notlike(f'%<p>{NOTIF_MODACTION_PREFIX}%')
|
||||||
).order_by(Notification.created_utc.desc())
|
).order_by(Notification.created_utc.desc())
|
||||||
|
|
||||||
if not (v and (v.shadowbanned or v.admin_level > 2)):
|
if not (v and (v.shadowbanned or v.admin_level > 2)):
|
||||||
|
@ -154,7 +172,8 @@ def notifications(v):
|
||||||
next_exists=next_exists,
|
next_exists=next_exists,
|
||||||
page=page,
|
page=page,
|
||||||
standalone=True,
|
standalone=True,
|
||||||
render_replies=True
|
render_replies=True,
|
||||||
|
NOTIF_MODACTION_JL_MIN=NOTIF_MODACTION_JL_MIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
<div class="row border-bottom bg-white w-200 pr-0" style="overflow: visible;">
|
<div class="row border-bottom bg-white w-200 pr-0" style="overflow: visible;">
|
||||||
<div class="col p-0 w-100">
|
<div class="col p-0 w-100">
|
||||||
<ul class="nav settings-nav" style="padding:0 0 0 20px">
|
<ul class="nav settings-nav" style="padding:0 0 0 20px" id="notifications--nav-list">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link py-3{% if not '=true' in request.full_path %} active{% endif %}" href="/notifications">
|
<a class="nav-link py-3{% if not '=true' in request.full_path %} active{% endif %}" href="/notifications">
|
||||||
All {% if v.normal_count %} <span class="font-weight-bold" style="color:red">({{v.normal_count}})</span>{% endif %}
|
All {% if v.normal_count %} <span class="font-weight-bold" style="color:red">({{v.normal_count}})</span>{% endif %}
|
||||||
|
@ -30,6 +30,13 @@
|
||||||
Messages
|
Messages
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% if v.admin_level >= NOTIF_MODACTION_JL_MIN %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link py-3{% if '/notifications?modactions=true' in request.full_path %} active{% endif %}" href="/notifications?modactions=true">
|
||||||
|
Modactions {% if v.modaction_notifications_count %}<span class="font-weight-bold" style="color:#e5990d">({{v.modaction_notifications_count}})</span>{% endif %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% if v.admin_level >= 2 %}
|
{% if v.admin_level >= 2 %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link py-3{% if '/notifications?modmail=true' in request.full_path %} active{% endif %}" href="/notifications?modmail=true">
|
<a class="nav-link py-3{% if '/notifications?modmail=true' in request.full_path %} active{% endif %}" href="/notifications?modmail=true">
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{%-
|
{%-
|
||||||
set CACHE_VER = {
|
set CACHE_VER = {
|
||||||
'css/main.css': 298,
|
'css/main.css': 299,
|
||||||
|
|
||||||
'css/4chan.css': 59,
|
'css/4chan.css': 59,
|
||||||
'css/classic.css': 59,
|
'css/classic.css': 59,
|
||||||
|
|
Loading…
Reference in New Issue