Merge branch 'frost' of https://github.com/Aevann1/rDrama into frost

master
Aevann1 2022-09-10 02:31:47 +02:00
commit 24c29bda04
3 changed files with 63 additions and 7 deletions

View File

@ -553,10 +553,27 @@ class User(Base):
@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.post_notifications_count \ - self.post_notifications_count \
- self.modaction_notifications_count \ - self.modaction_notifications_count \
- self.reddit_notifications_count - self.reddit_notifications_count
@property
@lazy
def message_notifications_count(self):
notifs = g.db.query(Notification).join(Comment).filter(
Notification.user_id == self.id,
Notification.read == False,
Comment.sentto != None,
or_(Comment.author_id==self.id, Comment.sentto==self.id),
Comment.parent_submission == None,
)
if not self.shadowbanned and self.admin_level < 3:
notifs = notifs.join(Comment.author).filter(User.shadowbanned == None)
return notifs.count()
@property @property
@lazy @lazy
def post_notifications_count(self): def post_notifications_count(self):
@ -599,6 +616,8 @@ class User(Base):
# only meaningful when notifications_count > 0; otherwise falsely '' ~ normal # only meaningful when notifications_count > 0; otherwise falsely '' ~ normal
if self.normal_notifications_count > 0: if self.normal_notifications_count > 0:
return '' return ''
elif self.message_notifications_count > 0:
return 'messages'
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:
@ -612,6 +631,7 @@ class User(Base):
def notifications_color(self): def notifications_color(self):
colors = { colors = {
'': '#dc3545', '': '#dc3545',
'messages': '#dc3545',
'posts': '#0000ff', 'posts': '#0000ff',
'modactions': '#e5990d', 'modactions': '#e5990d',
'reddit': '#805ad5', 'reddit': '#805ad5',

View File

@ -66,16 +66,51 @@ def notifications_messages(v):
try: page = max(int(request.values.get("page", 1)), 1) try: page = max(int(request.values.get("page", 1)), 1)
except: page = 1 except: page = 1
if v and (v.shadowbanned or v.admin_level > 2): # All of these queries are horrible. For whomever comes here after me,
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() # PLEASE just turn DMs into their own table and get them out of
else: # Notifications & Comments. It's worth it. Save yourself.
comments = g.db.query(Comment).join(Comment.author).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() message_threads = 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,
)
if not v.shadowbanned and v.admin_level < 3:
message_threads = message_threads.join(Comment.author) \
.filter(User.shadowbanned == None)
next_exists = (len(comments) > 25) thread_order = g.db.query(Comment.top_comment_id, Comment.created_utc) \
listing = comments[:25] .distinct(Comment.top_comment_id) \
.filter(
Comment.sentto != None,
or_(Comment.author_id == v.id, Comment.sentto == v.id),
).order_by(
Comment.top_comment_id.desc(),
Comment.created_utc.desc()
).subquery()
message_threads = message_threads.join(thread_order,
thread_order.c.top_comment_id == Comment.top_comment_id)
message_threads = message_threads.order_by(thread_order.c.created_utc.desc()) \
.offset(25*(page-1)).limit(26).all()
# Clear notifications (used for unread indicator only) for all user messages.
notifs_unread_row = g.db.query(Notification.comment_id).join(Comment).filter(
Notification.user_id == v.id,
Notification.read == False,
or_(Comment.author_id == v.id, Comment.sentto == v.id),
).all()
notifs_unread = [n.comment_id for n in notifs_unread_row]
g.db.query(Notification).filter(
Notification.user_id == v.id,
Notification.comment_id.in_(notifs_unread),
).update({Notification.read: True})
g.db.commit() g.db.commit()
next_exists = (len(message_threads) > 25)
listing = message_threads[:25]
if request.headers.get("Authorization"): return {"data":[x.json for x in listing]} if request.headers.get("Authorization"): return {"data":[x.json for x in listing]}
return render_template("notifications.html", return render_template("notifications.html",
@ -213,6 +248,7 @@ def notifications(v):
Comment.is_banned == False, Comment.is_banned == False,
Comment.deleted_utc == 0, Comment.deleted_utc == 0,
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/%'),
or_(Comment.sentto == None, Comment.sentto == 2),
).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)):

View File

@ -27,7 +27,7 @@
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link py-3{% if request.path == '/notifications/messages' %} active{% endif %}" href="/notifications/messages"> <a class="nav-link py-3{% if request.path == '/notifications/messages' %} active{% endif %}" href="/notifications/messages">
Messages Messages {% if v.message_notifications_count %}<span class="font-weight-bold" style="color:#ff0000">({{v.message_notifications_count}})</span>{% endif %}
</a> </a>
</li> </li>
{% if v.admin_level >= NOTIF_MODACTION_JL_MIN %} {% if v.admin_level >= NOTIF_MODACTION_JL_MIN %}