remotes/1693045480750635534/spooky-22
Aevann1 2022-04-04 01:15:57 +02:00
parent aaf3da70d2
commit 4e10e05dbb
1 changed files with 22 additions and 25 deletions

View File

@ -54,36 +54,34 @@ def notifications(v):
comments = comments[:25] comments = comments[:25]
comments = [x.parent_comm] comments = [x.parent_comm]
elif posts: elif posts:
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ID).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all() notifications = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(Notification.user_id == v.id, Comment.author_id == AUTOJANNY_ID).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all()
listing = [] listing = []
for index, x in enumerate(notifications[:100]): for index, n. c in enumerate(notifications[:100]):
c = x.comment if n.read and index > 24: break
if x.read and index > 24: break elif not n.read:
elif not x.read: n.read = True
x.read = True
c.unread = True c.unread = True
g.db.add(x) g.db.add(n)
if x.created_utc > 1620391248: c.notif_utc = x.created_utc if n.created_utc > 1620391248: c.notif_utc = n.created_utc
listing.append(c) listing.append(c)
g.db.commit() g.db.commit()
next_exists = (len(notifications) > len(listing)) next_exists = (len(notifications) > len(listing))
elif reddit: elif reddit:
notifications = v.notifications.join(Notification.comment).filter(Comment.body_html.like('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all() notifications = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(Notification.user_id == v.id, Comment.body_html.like('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all()
listing = [] listing = []
for index, x in enumerate(notifications[:100]): for index, n, c in enumerate(notifications[:100]):
c = x.comment if n.read and index > 24: break
if x.read and index > 24: break elif not n.read:
elif not x.read: n.read = True
x.read = True
c.unread = True c.unread = True
g.db.add(x) g.db.add(n)
if x.created_utc > 1620391248: c.notif_utc = x.created_utc if n.created_utc > 1620391248: c.notif_utc = n.created_utc
listing.append(c) listing.append(c)
g.db.commit() g.db.commit()
@ -95,20 +93,19 @@ def notifications(v):
Notification.user_id == v.id, Notification.user_id == v.id,
Comment.author_id != AUTOJANNY_ID, Comment.author_id != AUTOJANNY_ID,
Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%') Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')
) )
for x in unread: for n, c in unread:
x[0].read = True n.read = True
x[1].unread = True c.unread = True
g.db.add(x[0]) g.db.add(c)
g.db.commit() g.db.commit()
all = set([x.comment_id for x in v.notifications.join(Notification.comment).filter( all = set(x[0] for x in g.db.query(Notification.comment_id).join(Comment, Notification.comment_id == Comment.id).filter(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('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%') Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')
).order_by(Comment.top_comment_id.desc()).offset(50 * (page - 1)).limit(100).all()]) ).order_by(Comment.top_comment_id.desc()).offset(50 * (page - 1)).limit(100).all())
comments = g.db.query(Comment).join(Notification).distinct(Comment.top_comment_id).filter( comments = g.db.query(Comment).join(Notification).distinct(Comment.top_comment_id).filter(
Notification.user_id == v.id, Notification.user_id == v.id,
@ -131,7 +128,7 @@ def notifications(v):
while c.parent_comment and (c.parent_comment.author_id == v.id or c.parent_comment in comments): while c.parent_comment and (c.parent_comment.author_id == v.id or c.parent_comment in comments):
c = c.parent_comment c = c.parent_comment
c.replies2 = [x for x in c.child_comments if c.author_id == v.id or x.id in all] c.replies2 = [x for x in c.child_comments if c.author_id == v.id or x.id in all]
cids.update([x.id for x in c.replies2]) cids = cids | set(x.id for x in c.replies2)
cids.add(c.id) cids.add(c.id)
else: else:
while c.parent_comment: while c.parent_comment: