give jannoids notifs for deleted and removed comments

pull/83/head
Aevann1 2022-12-19 23:28:37 +02:00
parent 4997ba561a
commit c190fa89b2
2 changed files with 15 additions and 21 deletions

View File

@ -592,13 +592,15 @@ class User(Base):
.filter(
Notification.read == False,
Notification.user_id == self.id,
Comment.is_banned == False,
Comment.deleted_utc == 0,
not_(and_(Comment.sentto != None, Comment.sentto == MODMAIL_ID, User.is_muted)),
))
if not self.can_see_shadowbanned:
notifs = notifs.filter(User.shadowbanned == None)
notifs = notifs.filter(
User.shadowbanned == None,
Comment.is_banned == False,
Comment.deleted_utc == 0,
)
return notifs.count() + self.post_notifications_count + self.modaction_notifications_count + self.reddit_notifications_count

View File

@ -262,40 +262,32 @@ def notifications(v:User):
try: page = max(int(request.values.get("page", 1)), 1)
except: page = 1
if v.admin_level >= PERMS['USER_SHADOWBAN']:
unread_and_inaccessible = g.db.query(Notification).join(Notification.comment).filter(
Notification.user_id == v.id,
Notification.read == False,
or_(
Comment.is_banned != False,
Comment.deleted_utc != 0,
)
).all()
else:
if v.admin_level < PERMS['USER_SHADOWBAN']:
unread_and_inaccessible = g.db.query(Notification).join(Notification.comment).join(Comment.author).filter(
Notification.user_id == v.id,
Notification.read == False,
or_(
User.shadowbanned != None,
Comment.is_banned != False,
Comment.deleted_utc != 0,
User.shadowbanned != None,
)
).all()
for n in unread_and_inaccessible:
n.read = True
g.db.add(n)
for n in unread_and_inaccessible:
n.read = True
g.db.add(n)
comments = g.db.query(Comment, Notification).join(Notification.comment).join(Comment.author).filter(
Notification.user_id == v.id,
Comment.is_banned == False,
Comment.deleted_utc == 0,
or_(Comment.sentto == None, Comment.sentto == MODMAIL_ID),
not_(and_(Comment.sentto != None, Comment.sentto == MODMAIL_ID, User.is_muted)),
)
if v.admin_level < PERMS['USER_SHADOWBAN']:
comments = comments.filter(User.shadowbanned == None)
comments = comments.filter(
User.shadowbanned == None,
Comment.is_banned == False,
Comment.deleted_utc == 0,
)
comments = comments.order_by(Notification.created_utc.desc())
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE+1).all()