fsd
This commit is contained in:
parent
17b46cfb7f
commit
e33c46d186
1 changed files with 27 additions and 45 deletions
|
@ -32,6 +32,7 @@ def unread(v):
|
||||||
|
|
||||||
return {"data":[x.json for x in listing]}
|
return {"data":[x.json for x in listing]}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/notifications")
|
@app.get("/notifications")
|
||||||
@auth_required
|
@auth_required
|
||||||
def notifications(v):
|
def notifications(v):
|
||||||
|
@ -49,91 +50,73 @@ def notifications(v):
|
||||||
next_exists = (len(comments) > 25)
|
next_exists = (len(comments) > 25)
|
||||||
comments = comments[:25]
|
comments = comments[:25]
|
||||||
elif posts:
|
elif posts:
|
||||||
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.id.desc()).offset(25 * (page - 1)).limit(101).all()
|
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ID).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(101).all()
|
||||||
|
|
||||||
|
listing = []
|
||||||
|
|
||||||
for index, x in enumerate(notifications[:100]):
|
for index, x in enumerate(notifications[:100]):
|
||||||
if not x[0].read:
|
c = x.comment
|
||||||
x[0].read = True
|
if x.read and index > 24: break
|
||||||
x[1].unread = True
|
elif not x.read:
|
||||||
g.db.add(x[0])
|
x.read = True
|
||||||
|
c.unread = True
|
||||||
|
g.db.add(x)
|
||||||
|
listing.append(c)
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
listing = [x[1] for x in notifications][:25]
|
|
||||||
next_exists = (len(notifications) > len(listing))
|
next_exists = (len(notifications) > len(listing))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
notifications = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(
|
notifications = v.notifications.join(Notification.comment).filter(
|
||||||
Notification.user_id == v.id,
|
|
||||||
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,
|
||||||
).order_by(Notification.id.desc()).offset(100 * (page - 1)).limit(101).all()
|
).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all()
|
||||||
|
|
||||||
next_exists = (len(notifications) > 100)
|
next_exists = (len(notifications) > 25)
|
||||||
notifications = notifications[:100]
|
notifications = notifications[:25]
|
||||||
|
cids = [x.comment_id for x in notifications]
|
||||||
|
comments = get_comments(cids, v=v, load_parent=True)
|
||||||
|
|
||||||
|
i = 0
|
||||||
for x in notifications:
|
for x in notifications:
|
||||||
if x[0].read: break
|
try:
|
||||||
x[1].unread = True
|
if not x.read: comments[i].unread = True
|
||||||
x[0].read = True
|
except: continue
|
||||||
g.db.add(x[0])
|
x.read = True
|
||||||
|
g.db.add(x)
|
||||||
|
i += 1
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
comments = [x[1] for x in notifications]
|
|
||||||
|
|
||||||
if not posts:
|
if not posts:
|
||||||
listing = []
|
listing = []
|
||||||
all = set()
|
|
||||||
for c in comments:
|
for c in comments:
|
||||||
c.is_blocked = False
|
c.is_blocked = False
|
||||||
c.is_blocking = False
|
c.is_blocking = False
|
||||||
if c.parent_submission and c.parent_comment and c.parent_comment.author_id == v.id:
|
if c.parent_submission and c.parent_comment and c.parent_comment.author_id == v.id:
|
||||||
replies = []
|
c.replies = []
|
||||||
for x in c.replies:
|
while c.parent_comment and c.parent_comment.author_id == v.id:
|
||||||
if x.author_id == v.id:
|
|
||||||
x.voted = 1
|
|
||||||
replies.append(x)
|
|
||||||
all.add(x.id)
|
|
||||||
c.replies = replies
|
|
||||||
|
|
||||||
while c.parent_comment and (c.parent_comment.author_id == v.id or c.parent_comment in comments):
|
|
||||||
parent = c.parent_comment
|
parent = c.parent_comment
|
||||||
if c not in parent.replies2:
|
if c not in parent.replies2:
|
||||||
parent.replies2 = parent.replies2 + [c]
|
parent.replies2 = parent.replies2 + [c]
|
||||||
all.add(c.id)
|
|
||||||
parent.replies = parent.replies2
|
parent.replies = parent.replies2
|
||||||
c = parent
|
c = parent
|
||||||
|
|
||||||
if c not in listing:
|
if c not in listing:
|
||||||
all.add(c.id)
|
|
||||||
listing.append(c)
|
listing.append(c)
|
||||||
c.replies = c.replies2
|
c.replies = c.replies2
|
||||||
elif c.parent_submission:
|
elif c.parent_submission:
|
||||||
replies = []
|
c.replies = []
|
||||||
for x in c.replies:
|
|
||||||
if x.author_id == v.id:
|
|
||||||
x.voted = 1
|
|
||||||
replies.append(x)
|
|
||||||
all.add(x.id)
|
|
||||||
c.replies = replies
|
|
||||||
if c not in listing:
|
if c not in listing:
|
||||||
all.add(c.id)
|
|
||||||
listing.append(c)
|
listing.append(c)
|
||||||
else:
|
else:
|
||||||
if c.parent_comment:
|
if c.parent_comment:
|
||||||
while c.level > 1:
|
while c.level > 1:
|
||||||
all.add(c.id)
|
|
||||||
c = c.parent_comment
|
c = c.parent_comment
|
||||||
|
|
||||||
if c not in listing:
|
if c not in listing:
|
||||||
all.add(c.id)
|
|
||||||
listing.append(c)
|
listing.append(c)
|
||||||
|
|
||||||
all = all | set([x.id for x in comments]) | set([x.id for x in listing])
|
|
||||||
comments = get_comments(all, v=v)
|
|
||||||
|
|
||||||
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",
|
||||||
|
@ -146,7 +129,6 @@ def notifications(v):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
@app.get("/logged_out")
|
@app.get("/logged_out")
|
||||||
@limiter.limit("3/second;30/minute;400/hour;2000/day")
|
@limiter.limit("3/second;30/minute;400/hour;2000/day")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue