forked from rDrama/rDrama
dsf
parent
6fef346703
commit
c371b11289
|
@ -38,7 +38,6 @@ def unread(v):
|
||||||
@auth_required
|
@auth_required
|
||||||
def notifications(v):
|
def notifications(v):
|
||||||
t = time.time()
|
t = time.time()
|
||||||
|
|
||||||
try: page = int(request.values.get('page', 1))
|
try: page = int(request.values.get('page', 1))
|
||||||
except: page = 1
|
except: page = 1
|
||||||
messages = request.values.get('messages')
|
messages = request.values.get('messages')
|
||||||
|
@ -50,9 +49,10 @@ def notifications(v):
|
||||||
next_exists = (len(comments) > 25)
|
next_exists = (len(comments) > 25)
|
||||||
comments = comments[:25]
|
comments = comments[:25]
|
||||||
elif messages:
|
elif messages:
|
||||||
comments = g.db.query(Comment).filter(Comment.sentto != None, or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, not_(Comment.child_comments.any())).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all()
|
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()
|
||||||
next_exists = (len(comments) > 25)
|
next_exists = (len(comments) > 25)
|
||||||
comments = comments[:25]
|
comments = comments[:25]
|
||||||
|
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 = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ID).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all()
|
||||||
|
|
||||||
|
@ -90,38 +90,49 @@ def notifications(v):
|
||||||
|
|
||||||
next_exists = (len(notifications) > len(listing))
|
next_exists = (len(notifications) > len(listing))
|
||||||
else:
|
else:
|
||||||
notifications = v.notifications.join(Notification.comment).distinct(Comment.top_comment_id).filter(
|
unread = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(
|
||||||
|
Notification.read == False,
|
||||||
|
Notification.user_id == v.id,
|
||||||
|
Comment.author_id != AUTOJANNY_ID,
|
||||||
|
Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')
|
||||||
|
)
|
||||||
|
for x in unread:
|
||||||
|
x[0].read = True
|
||||||
|
x[1].unread = True
|
||||||
|
g.db.add(x[0])
|
||||||
|
g.db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
all = set([x.comment_id for x in v.notifications.join(Notification.comment).filter(
|
||||||
|
Comment.is_banned == False,
|
||||||
|
Comment.deleted_utc == 0,
|
||||||
|
Comment.author_id != AUTOJANNY_ID,
|
||||||
|
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()])
|
||||||
|
|
||||||
|
comments = g.db.query(Comment).join(Notification).distinct(Comment.top_comment_id).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,
|
||||||
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(51).all()
|
).order_by(Comment.top_comment_id.desc()).offset(50 * (page - 1)).limit(51).all()
|
||||||
|
|
||||||
next_exists = (len(notifications) > 50)
|
next_exists = (len(comments) > 50)
|
||||||
notifications = notifications[:50]
|
comments = comments[:50]
|
||||||
cids = [x.comment_id for x in notifications]
|
|
||||||
comments = get_comments(cids, v=v, load_parent=True)
|
|
||||||
|
|
||||||
i = 0
|
|
||||||
for x in notifications:
|
cids = set()
|
||||||
try: c = comments[i]
|
|
||||||
except: continue
|
|
||||||
if not x.read: c.unread = True
|
|
||||||
if x.created_utc > 1620391248: c.notif_utc = x.created_utc
|
|
||||||
x.read = True
|
|
||||||
g.db.add(x)
|
|
||||||
i += 1
|
|
||||||
g.db.commit()
|
|
||||||
|
|
||||||
if not posts and not reddit:
|
if not posts and not reddit:
|
||||||
listing = []
|
listing = []
|
||||||
for c in comments:
|
for c in comments:
|
||||||
if c.parent_submission:
|
if c.parent_submission:
|
||||||
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):
|
||||||
parent = c.parent_comment
|
c = c.parent_comment
|
||||||
if parent.replies2 == None: parent.replies2 = [c]
|
c.replies2 = [x for x in c.child_comments if c.author_id == v.id or x.id in all]
|
||||||
elif c not in parent.replies2: parent.replies2.append(c)
|
cids.update([x.id for x in c.replies2])
|
||||||
c = parent
|
cids.add(c.id)
|
||||||
else:
|
else:
|
||||||
while c.parent_comment:
|
while c.parent_comment:
|
||||||
c = c.parent_comment
|
c = c.parent_comment
|
||||||
|
@ -129,10 +140,11 @@ def notifications(v):
|
||||||
|
|
||||||
if c not in listing: listing.append(c)
|
if c not in listing: listing.append(c)
|
||||||
|
|
||||||
|
if c.parent_submission: comms = get_comments(list(cids), 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]}
|
||||||
|
|
||||||
print(time.time() - t)
|
print(time.time() - t, flush=True)
|
||||||
return render_template("notifications.html",
|
return render_template("notifications.html",
|
||||||
v=v,
|
v=v,
|
||||||
notifications=listing,
|
notifications=listing,
|
||||||
|
|
Loading…
Reference in New Issue