move modmail notifs to their already-existing section

master
Aevann 2024-02-01 02:30:12 +02:00
parent 3ee054d152
commit 33e922a9dd
7 changed files with 45 additions and 72 deletions

View File

@ -139,6 +139,7 @@ class User(Base):
currently_held_lottery_tickets = Column(Integer, default=0) currently_held_lottery_tickets = Column(Integer, default=0)
total_held_lottery_tickets = Column(Integer, default=0) total_held_lottery_tickets = Column(Integer, default=0)
total_lottery_winnings = Column(Integer, default=0) total_lottery_winnings = Column(Integer, default=0)
last_viewed_modmail_notifs = Column(Integer, default=0)
last_viewed_post_notifs = Column(Integer, default=0) last_viewed_post_notifs = Column(Integer, default=0)
last_viewed_log_notifs = Column(Integer, default=0) last_viewed_log_notifs = Column(Integer, default=0)
last_viewed_reddit_notifs = Column(Integer, default=0) last_viewed_reddit_notifs = Column(Integer, default=0)
@ -744,11 +745,6 @@ class User(Base):
Notification.user_id == self.id, Notification.user_id == self.id,
)) ))
if self.admin_level >= PERMS['VIEW_MODMAIL']:
notifs = notifs.filter(
not_(and_(Comment.sentto != None, Comment.sentto == MODMAIL_ID, User.is_muted))
)
if not self.admin_level >= PERMS['USER_SHADOWBAN']: if not self.admin_level >= PERMS['USER_SHADOWBAN']:
notifs = notifs.filter( notifs = notifs.filter(
User.shadowbanned == None, User.shadowbanned == None,
@ -756,13 +752,14 @@ class User(Base):
Comment.deleted_utc == 0, Comment.deleted_utc == 0,
) )
return notifs.count() + self.post_notifications_count + self.modaction_notifications_count + self.reddit_notifications_count return notifs.count() + self.modmail_notifications_count + self.post_notifications_count + self.modaction_notifications_count + self.reddit_notifications_count
@property @property
@lazy @lazy
def normal_notifications_count(self): def normal_notifications_count(self):
return self.notifications_count \ return self.notifications_count \
- self.message_notifications_count \ - self.message_notifications_count \
- self.modmail_notifications_count \
- self.post_notifications_count \ - self.post_notifications_count \
- self.modaction_notifications_count \ - self.modaction_notifications_count \
- self.reddit_notifications_count - self.reddit_notifications_count
@ -783,6 +780,17 @@ class User(Base):
return notifs.count() return notifs.count()
@property
@lazy
def modmail_notifications_count(self):
if self.admin_level < PERMS['NOTIFICATIONS_MODMAIL']:
return 0
return g.db.query(Comment).filter(
Comment.author_id != self.id,
Comment.sentto == MODMAIL_ID,
Comment.created_utc > self.last_viewed_modmail_notifs,
).count()
@property @property
@lazy @lazy
def post_notifications_count(self): def post_notifications_count(self):
@ -852,6 +860,8 @@ class User(Base):
return '' return ''
elif self.message_notifications_count > 0: elif self.message_notifications_count > 0:
return 'messages' return 'messages'
elif self.modmail_notifications_count > 0:
return 'modmail'
elif self.post_notifications_count > 0: elif self.post_notifications_count > 0:
return 'posts' return 'posts'
elif self.modaction_notifications_count > 0: elif self.modaction_notifications_count > 0:
@ -866,6 +876,7 @@ class User(Base):
colors = { colors = {
'': '#dc3545', '': '#dc3545',
'messages': '#d8910d', 'messages': '#d8910d',
'modmail': '#f15387',
'posts': '#0000ff', 'posts': '#0000ff',
'modactions': '#1ad80d', 'modactions': '#1ad80d',
'reddit': '#805ad5', 'reddit': '#805ad5',
@ -873,20 +884,6 @@ class User(Base):
return colors[self.notifications_do] if self.notifications_do \ return colors[self.notifications_do] if self.notifications_do \
else colors[''] else colors['']
@property
@lazy
def do_posts(self):
return self.post_notifications_count and \
self.post_notifications_count == (
self.notifications_count
- self.modaction_notifications_count
- self.reddit_notifications_count)
@property
@lazy
def do_reddit(self):
return self.notifications_count == self.reddit_notifications_count
@property @property
@lazy @lazy
def moderated_holes(self): def moderated_holes(self):

View File

@ -270,7 +270,7 @@ def messagereply(v):
if v.is_permabanned and parent.sentto != MODMAIL_ID: if v.is_permabanned and parent.sentto != MODMAIL_ID:
abort(403, "You are permabanned and may not reply to messages!") abort(403, "You are permabanned and may not reply to messages!")
elif v.is_muted and parent.sentto == MODMAIL_ID: elif v.is_muted and parent.sentto == MODMAIL_ID:
abort(403, "You are forbidden from replying to modmail!") abort(403, "You are muted!")
if parent.sentto == MODMAIL_ID: user_id = None if parent.sentto == MODMAIL_ID: user_id = None
elif v.id == user_id: user_id = parent.sentto elif v.id == user_id: user_id = parent.sentto
@ -332,25 +332,8 @@ def messagereply(v):
top_comment = c.top_comment top_comment = c.top_comment
if top_comment.sentto == MODMAIL_ID: if top_comment.sentto == MODMAIL_ID:
admin_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_MODMAIL'], User.id != v.id)] if parent.author.id != v.id and parent.author.admin_level < PERMS['VIEW_MODMAIL']:
notif = Notification(comment_id=c.id, user_id=parent.author.id)
if SITE == 'watchpeopledie.tv':
if AEVANN_ID in admin_ids:
admin_ids.remove(AEVANN_ID)
if 'delete' in top_comment.body.lower() and 'account' in top_comment.body.lower():
admin_ids.remove(15447)
if parent.author.id not in admin_ids + [v.id]:
admin_ids.append(parent.author.id)
#Don't delete unread notifications, so the replies don't get collapsed and they get highlighted
ids = [top_comment.id] + [x.id for x in top_comment.replies(sort="old")]
notifications = g.db.query(Notification).filter(Notification.read == True, Notification.comment_id.in_(ids), Notification.user_id.in_(admin_ids))
for n in notifications:
g.db.delete(n)
for admin in admin_ids:
notif = Notification(comment_id=c.id, user_id=admin)
g.db.add(notif) g.db.add(notif)
elif user_id and user_id not in {v.id, MODMAIL_ID} | BOT_IDs: elif user_id and user_id not in {v.id, MODMAIL_ID} | BOT_IDs:
c.unread = True c.unread = True

View File

@ -29,6 +29,7 @@ def clear(v):
n.read = True n.read = True
g.db.add(n) g.db.add(n)
v.last_viewed_modmail_notifs = int(time.time())
v.last_viewed_post_notifs = int(time.time()) v.last_viewed_post_notifs = int(time.time())
v.last_viewed_log_notifs = int(time.time()) v.last_viewed_log_notifs = int(time.time())
v.last_viewed_reddit_notifs = int(time.time()) v.last_viewed_reddit_notifs = int(time.time())
@ -70,6 +71,15 @@ def notifications_modmail(v):
total = comments.count() total = comments.count()
listing = comments.order_by(Comment.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all() listing = comments.order_by(Comment.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
for c in listing:
c_and_children = [c] + c.replies('old')
for c in c_and_children:
c.unread = c.created_utc > v.last_viewed_modmail_notifs
if not session.get("GLOBAL") and not request.values.get('nr'):
v.last_viewed_modmail_notifs = int(time.time())
g.db.add(v)
if v.client: return {"data":[x.json for x in listing]} if v.client: return {"data":[x.json for x in listing]}
return render_template("notifications.html", return render_template("notifications.html",
@ -320,11 +330,6 @@ def notifications(v):
or_(Comment.sentto == None, Comment.sentto != v.id), or_(Comment.sentto == None, Comment.sentto != v.id),
) )
if v.admin_level >= PERMS['VIEW_MODMAIL']:
comments = comments.join(Comment.author).filter(
not_(and_(Comment.sentto != None, Comment.sentto == MODMAIL_ID, User.is_muted))
)
if v.admin_level < PERMS['USER_SHADOWBAN']: if v.admin_level < PERMS['USER_SHADOWBAN']:
comments = comments.filter( comments = comments.filter(
Comment.is_banned == False, Comment.is_banned == False,

View File

@ -293,7 +293,7 @@ def submit_contact(v):
if not body: abort(400) if not body: abort(400)
if v.is_muted: if v.is_muted:
abort(403) abort(403, "You are muted!")
body = process_files(request.files, v, body) body = process_files(request.files, v, body)
body = body.strip() body = body.strip()
@ -314,20 +314,6 @@ def submit_contact(v):
execute_under_siege(v, new_comment, new_comment.body_html, 'modmail') execute_under_siege(v, new_comment, new_comment.body_html, 'modmail')
new_comment.top_comment_id = new_comment.id new_comment.top_comment_id = new_comment.id
admin_ids = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_MODMAIL'])]
if SITE == 'watchpeopledie.tv':
if AEVANN_ID in admin_ids:
admin_ids.remove(AEVANN_ID)
if 'delete' in new_comment.body.lower() and 'account' in new_comment.body.lower():
admin_ids.remove(15447)
for admin_id in admin_ids:
notif = Notification(comment_id=new_comment.id, user_id=admin_id)
g.db.add(notif)
push_notif(admin_ids, f'New modmail from @{new_comment.author_name}', new_comment.body, f'{SITE_FULL}/notifications/modmail')
return {"message": "Your message has been sent to the admins!"} return {"message": "Your message has been sent to the admins!"}
@cache.memoize(timeout=3600) @cache.memoize(timeout=3600)

View File

@ -19,6 +19,13 @@
Messages {% if v.message_notifications_count %}<span class="font-weight-bold" style="color:#d8910d">({{v.message_notifications_count}})</span>{% endif %} Messages {% if v.message_notifications_count %}<span class="font-weight-bold" style="color:#d8910d">({{v.message_notifications_count}})</span>{% endif %}
</a> </a>
</li> </li>
{% if v.admin_level >= PERMS['VIEW_MODMAIL'] %}
<li class="nav-item">
<a class="nav-link py-3{% if request.path == '/notifications/modmail' %} active{% endif %}" href="/notifications/modmail">
Modmail {% if v.modmail_notifications_count %}<span class="font-weight-bold" style="color:#f15387">({{v.modmail_notifications_count}})</span>{% endif %}
</a>
</li>
{% endif %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link py-3{% if request.path == '/notifications/posts' %} active{% endif %}" href="/notifications/posts"> <a class="nav-link py-3{% if request.path == '/notifications/posts' %} active{% endif %}" href="/notifications/posts">
Posts {% if v.post_notifications_count %}<span class="font-weight-bold" style="color:#0000ff">({{v.post_notifications_count}})</span>{% endif %} Posts {% if v.post_notifications_count %}<span class="font-weight-bold" style="color:#0000ff">({{v.post_notifications_count}})</span>{% endif %}
@ -31,13 +38,6 @@
</a> </a>
</li> </li>
{% endif %} {% endif %}
{% if v.admin_level >= PERMS['VIEW_MODMAIL'] %}
<li class="nav-item">
<a class="nav-link py-3{% if request.path == '/notifications/modmail' %} active{% endif %}" href="/notifications/modmail">
Modmail
</a>
</li>
{% endif %}
{% if v.can_view_offsitementions %} {% if v.can_view_offsitementions %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link py-3{% if request.path == '/notifications/reddit' %} active{% endif %}" href="/notifications/reddit"> <a class="nav-link py-3{% if request.path == '/notifications/reddit' %} active{% endif %}" href="/notifications/reddit">

View File

@ -0,0 +1,2 @@
alter table users add column last_viewed_modmail_notifs int not null default 0;
alter table users alter column last_viewed_modmail_notifs drop default;

View File

@ -2,21 +2,21 @@ INSERT INTO public.users (
username, passhash, created_utc, admin_level, email_verified, username, passhash, created_utc, admin_level, email_verified,
original_username, defaultsorting, defaultsortingcomments, defaulttime, namecolor, flaircolor, theme, themecolor, original_username, defaultsorting, defaultsortingcomments, defaulttime, namecolor, flaircolor, theme, themecolor,
reddit, pronouns, verified, profileurl, highres, reddit, pronouns, verified, profileurl, highres,
marsify, last_viewed_post_notifs, last_viewed_log_notifs, last_viewed_reddit_notifs, lifetimedonated, lifetimedonated_visible, show_sigs, grinch marsify, last_viewed_modmail_notifs, last_viewed_post_notifs, last_viewed_log_notifs, last_viewed_reddit_notifs, lifetimedonated, lifetimedonated_visible, show_sigs, grinch
) VALUES ) VALUES
('AutoJanny', '', extract(epoch from now()), 0, true, ('AutoJanny', '', extract(epoch from now()), 0, true,
'AutoJanny', 'hot', 'top', 'day', 'ff459a', 'ff459a', 'dark', 'ff459a', 'AutoJanny', 'hot', 'top', 'day', 'ff459a', 'ff459a', 'dark', 'ff459a',
'old.reddit.com', 'clean/it/up', 'Verified', '/i/pfps/1.webp', '/i/pfps/1.webp', 'old.reddit.com', 'clean/it/up', 'Verified', '/i/pfps/1.webp', '/i/pfps/1.webp',
0, 0, 0, 0, 0, false, true, false), 0, 0, 0, 0, 0, 0, false, true, false),
('Snappy', '', extract(epoch from now()), 0, true, ('Snappy', '', extract(epoch from now()), 0, true,
'Snappy', 'hot', 'top', 'day', '62ca56', 'e4432d', 'dark', '30409f', 'Snappy', 'hot', 'top', 'day', '62ca56', 'e4432d', 'dark', '30409f',
'old.reddit.com', 'beep/boop', 'Verified', '/i/pfps/2.webp', '/i/pfps/2.webp', 'old.reddit.com', 'beep/boop', 'Verified', '/i/pfps/2.webp', '/i/pfps/2.webp',
0, 0, 0, 0, 0, false, true, false), 0, 0, 0, 0, 0, 0, false, true, false),
('longpostbot', '', extract(epoch from now()), 0, true, ('longpostbot', '', extract(epoch from now()), 0, true,
'longpostbot', 'hot', 'top', 'day', '62ca56', 'e4432d', 'dark', '30409f', 'longpostbot', 'hot', 'top', 'day', '62ca56', 'e4432d', 'dark', '30409f',
'old.reddit.com', 'tl/dr', 'Verified', '/i/pfps/3.webp', '/i/pfps/3.webp', 'old.reddit.com', 'tl/dr', 'Verified', '/i/pfps/3.webp', '/i/pfps/3.webp',
0, 0, 0, 0, 0, false, true, false), 0, 0, 0, 0, 0, 0, false, true, false),
('zozbot', '', extract(epoch from now()), 0, true, ('zozbot', '', extract(epoch from now()), 0, true,
'zozbot', 'hot', 'top', 'day', '62ca56', 'e4432d', 'dark', '30409f', 'zozbot', 'hot', 'top', 'day', '62ca56', 'e4432d', 'dark', '30409f',
'old.reddit.com', 'zoz/zle', 'Verified', '/i/pfps/4.webp', '/i/pfps/4.webp', 'old.reddit.com', 'zoz/zle', 'Verified', '/i/pfps/4.webp', '/i/pfps/4.webp',
0, 0, 0, 0, 0, false, true, false); 0, 0, 0, 0, 0, 0, false, true, false);