master
Aevann1 2021-09-17 10:02:13 +02:00
parent ad0f60bf68
commit 507be101f7
1 changed files with 101 additions and 0 deletions

View File

@ -114,6 +114,107 @@ def notifications(v):
is_notification_page=True)
@app.get("/notifications2")
@auth_required
def notifications2(v):
try: page = int(request.args.get('page', 1))
except: page = 1
messages = request.args.get('messages', False)
modmail = request.args.get('modmail', False)
posts = request.args.get('posts', False)
if modmail and v.admin_level == 6:
comments = g.db.query(Comment).filter(Comment.sentto==0).order_by(Comment.created_utc.desc()).offset(25*(page-1)).limit(26).all()
next_exists = (len(comments) > 25)
comments = comments[:25]
elif messages:
comments = g.db.query(Comment).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None).order_by(Comment.created_utc.desc(), not_(Comment.child_comments.any())).offset(25*(page-1)).limit(26).all()
next_exists = (len(comments) > 25)
comments = comments[:25]
elif posts:
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all()
comments = []
t = time.time()
for index, x in enumerate(notifications):
c = x.comment
if x.read and index > 26: break
elif not x.read:
c.unread = True
x.read = True
g.db.add(x)
comments.append(c)
g.db.commit()
print(time.time() - t)
next_exists = (len(comments) > 25)
listing = comments[:25]
else:
notifications = v.notifications.join(Notification.comment).filter(
Comment.is_banned == False,
Comment.deleted_utc == 0,
Comment.author_id != AUTOJANNY_ACCOUNT,
).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all()
next_exists = (len(notifications) > 25)
notifications = notifications[:25]
cids = [x.comment_id for x in notifications]
comments = get_comments(cids, v=v, load_parent=True)
notifs = []
i = 0
for x in notifications:
try:
if not x.read: comments[i].unread = True
except: continue
notifs.append({'id': x.id, 'read': True})
i += 1
g.db.bulk_update_mappings(Notification, notifs)
g.db.commit()
if not posts:
listing = []
for c in comments:
c._is_blocked = False
c._is_blocking = False
if c.parent_submission and c.parent_comment and c.parent_comment.author_id == v.id:
c.replies = []
while c.parent_comment and c.parent_comment.author_id == v.id:
parent = c.parent_comment
if c not in parent.replies2:
parent.replies2 = parent.replies2 + [c]
parent.replies = parent.replies2
c = parent
if c not in listing:
listing.append(c)
c.replies = c.replies2
elif c.parent_submission:
c.replies = []
if c not in listing:
listing.append(c)
else:
if c.parent_comment:
while c.level > 1:
c = c.parent_comment
if c not in listing:
listing.append(c)
return render_template("notifications.html",
v=v,
notifications=listing,
next_exists=next_exists,
page=page,
standalone=True,
render_replies=True,
is_notification_page=True)
@cache.memoize(timeout=86400)
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', **kwargs):