forked from rDrama/rDrama
fdMerge branch 'frost' of https://github.com/Aevann1/Drama into frost
commit
e6ffec4312
|
@ -54,7 +54,7 @@ class Comment(Base):
|
||||||
author = relationship("User", primaryjoin="User.id==Comment.author_id")
|
author = relationship("User", primaryjoin="User.id==Comment.author_id")
|
||||||
senttouser = relationship("User", primaryjoin="User.id==Comment.sentto", viewonly=True)
|
senttouser = relationship("User", primaryjoin="User.id==Comment.sentto", viewonly=True)
|
||||||
parent_comment = relationship("Comment", remote_side=[id], viewonly=True)
|
parent_comment = relationship("Comment", remote_side=[id], viewonly=True)
|
||||||
child_comments = relationship("Comment", remote_side=[parent_comment_id], viewonly=True)
|
child_comments = relationship("Comment", lazy="dynamic", remote_side=[parent_comment_id], viewonly=True)
|
||||||
awards = relationship("AwardRelationship", viewonly=True)
|
awards = relationship("AwardRelationship", viewonly=True)
|
||||||
reports = relationship("CommentFlag", viewonly=True)
|
reports = relationship("CommentFlag", viewonly=True)
|
||||||
|
|
||||||
|
|
|
@ -187,11 +187,6 @@ class User(Base):
|
||||||
def csslazy(self):
|
def csslazy(self):
|
||||||
return self.css
|
return self.css
|
||||||
|
|
||||||
@property
|
|
||||||
@lazy
|
|
||||||
def notifications(self):
|
|
||||||
return g.db.query(Notification).filter_by(user_id=self.id)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def created_date(self):
|
def created_date(self):
|
||||||
|
|
|
@ -9,7 +9,8 @@ defaulttimefilter = environ.get("DEFAULT_TIME_FILTER", "all").strip()
|
||||||
@app.post("/clear")
|
@app.post("/clear")
|
||||||
@auth_required
|
@auth_required
|
||||||
def clear(v):
|
def clear(v):
|
||||||
for n in v.notifications.filter_by(read=False).all():
|
notifs = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(Notification.read == False, Notification.user_id == v.id).all()
|
||||||
|
for n in notifs:
|
||||||
n.read = True
|
n.read = True
|
||||||
g.db.add(n)
|
g.db.add(n)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
@ -18,7 +19,7 @@ def clear(v):
|
||||||
@app.get("/unread")
|
@app.get("/unread")
|
||||||
@auth_required
|
@auth_required
|
||||||
def unread(v):
|
def unread(v):
|
||||||
listing = g.db.query(Comment).join(Notification.comment).filter(
|
listing = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(
|
||||||
Notification.read == False,
|
Notification.read == False,
|
||||||
Notification.user_id == v.id,
|
Notification.user_id == v.id,
|
||||||
Comment.is_banned == False,
|
Comment.is_banned == False,
|
||||||
|
@ -26,17 +27,18 @@ def unread(v):
|
||||||
Comment.author_id != AUTOJANNY_ID,
|
Comment.author_id != AUTOJANNY_ID,
|
||||||
).order_by(Notification.created_utc.desc()).all()
|
).order_by(Notification.created_utc.desc()).all()
|
||||||
|
|
||||||
for n in v.notifications.filter_by(read=False).all():
|
for n, c in listing:
|
||||||
n.read = True
|
n.read = True
|
||||||
g.db.add(n)
|
g.db.add(n)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
return {"data":[x.json for x in listing]}
|
return {"data":[x[1].json for x in listing]}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/notifications")
|
@app.get("/notifications")
|
||||||
@auth_required
|
@auth_required
|
||||||
def notifications(v):
|
def notifications(v):
|
||||||
|
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')
|
||||||
|
@ -46,89 +48,98 @@ def notifications(v):
|
||||||
if modmail and v.admin_level > 1:
|
if modmail and v.admin_level > 1:
|
||||||
comments = g.db.query(Comment).filter(Comment.sentto==2).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all()
|
comments = g.db.query(Comment).filter(Comment.sentto==2).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]
|
listing = 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]
|
listing = comments[:25]
|
||||||
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, x in enumerate(notifications[:100]):
|
||||||
c = x.comment
|
n, c = x
|
||||||
if x.read and index > 24: break
|
if n.read and index > 24: break
|
||||||
elif not x.read:
|
elif not n.read:
|
||||||
x.read = True
|
n.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, x in enumerate(notifications[:100]):
|
||||||
c = x.comment
|
n, c = x
|
||||||
if x.read and index > 24: break
|
if n.read and index > 24: break
|
||||||
elif not x.read:
|
elif not n.read:
|
||||||
x.read = True
|
n.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))
|
||||||
else:
|
else:
|
||||||
notifications = v.notifications.join(Notification.comment).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 n, c in unread:
|
||||||
|
n.read = True
|
||||||
|
c.unread = True
|
||||||
|
g.db.add(c)
|
||||||
|
g.db.commit()
|
||||||
|
|
||||||
|
sq = g.db.query(Comment.id).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(Notification.created_utc.desc()).offset(50 * (page - 1)).limit(51).all()
|
).order_by(Comment.top_comment_id.desc()).subquery()
|
||||||
|
|
||||||
next_exists = (len(notifications) > 50)
|
comments = g.db.query(Comment).join(sq, sq.c.id == Comment.id).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all()
|
||||||
notifications = notifications[:50]
|
|
||||||
cids = [x.comment_id for x in notifications]
|
|
||||||
comments = get_comments(cids, v=v, load_parent=True)
|
|
||||||
|
|
||||||
i = 0
|
next_exists = (len(comments) > 25)
|
||||||
for x in notifications:
|
comments = comments[:25]
|
||||||
try: c = comments[i]
|
|
||||||
except: continue
|
cids = set([x[0] for x in g.db.query(Comment.id).join(Notification).filter(
|
||||||
if not x.read: c.unread = True
|
Notification.user_id == v.id,
|
||||||
if x.created_utc > 1620391248: c.notif_utc = x.created_utc
|
Comment.is_banned == False,
|
||||||
x.read = True
|
Comment.deleted_utc == 0,
|
||||||
g.db.add(x)
|
Comment.author_id != AUTOJANNY_ID,
|
||||||
i += 1
|
Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')
|
||||||
g.db.commit()
|
).order_by(Comment.top_comment_id.desc()).offset(25 * (page - 1)).limit(1000).all()] + [x.id for x in comments])
|
||||||
|
|
||||||
|
comms = get_comments(list(cids), v=v)
|
||||||
|
|
||||||
if not posts and not reddit:
|
|
||||||
listing = []
|
listing = []
|
||||||
for c in comments:
|
for c in comments:
|
||||||
if c.parent_submission:
|
if c.parent_submission:
|
||||||
|
if c.replies2 == None:
|
||||||
|
c.replies2 = c.child_comments.filter(or_(Comment.author_id == v.id, Comment.id.in_(cids))).all()
|
||||||
|
for x in c.replies2:
|
||||||
|
if x.replies2 == None: x.replies2 = []
|
||||||
|
while c.parent_comment and (c.parent_comment.author_id == v.id or c.parent_comment.id in cids):
|
||||||
|
c = c.parent_comment
|
||||||
|
if c.replies2 == None:
|
||||||
|
c.replies2 = c.child_comments.filter(or_(Comment.author_id == v.id, Comment.id.in_(cids))).all()
|
||||||
|
for x in c.replies2:
|
||||||
|
if x.replies2 == None: x.replies2 = []
|
||||||
|
|
||||||
if c.replies2 == None: c.replies2 = []
|
cids.add(c.id)
|
||||||
for x in c.child_comments:
|
|
||||||
if x.author_id == v.id:
|
|
||||||
x.voted = 1
|
|
||||||
if x not in c.replies2: c.replies2.append(x)
|
|
||||||
|
|
||||||
while c.parent_comment and (c.parent_comment.author_id == v.id or c.parent_comment in comments):
|
|
||||||
parent = c.parent_comment
|
|
||||||
if parent.replies2 == None: parent.replies2 = [c]
|
|
||||||
elif c not in parent.replies2: parent.replies2.append(c)
|
|
||||||
c = parent
|
|
||||||
|
|
||||||
if c.replies2 == None: c.replies2 = []
|
|
||||||
else:
|
else:
|
||||||
while c.parent_comment:
|
while c.parent_comment:
|
||||||
c = c.parent_comment
|
c = c.parent_comment
|
||||||
|
@ -136,9 +147,9 @@ def notifications(v):
|
||||||
|
|
||||||
if c not in listing: listing.append(c)
|
if c not in listing: listing.append(c)
|
||||||
|
|
||||||
|
|
||||||
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("5: " + str(time.time() - t), flush=True)
|
||||||
return render_template("notifications.html",
|
return render_template("notifications.html",
|
||||||
v=v,
|
v=v,
|
||||||
notifications=listing,
|
notifications=listing,
|
||||||
|
|
|
@ -111,11 +111,12 @@
|
||||||
{% set score=c.score %}
|
{% set score=c.score %}
|
||||||
|
|
||||||
{% if v %}
|
{% if v %}
|
||||||
{% set voted=c.voted %}
|
{% set voted=c.voted %}
|
||||||
|
{% if not voted and v.id == c.author_id %}
|
||||||
|
{% set voted=1 %}
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set voted=-2 %}
|
{% set voted=-2 %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if standalone and level==1 %}
|
{% if standalone and level==1 %}
|
||||||
|
|
|
@ -29,17 +29,23 @@
|
||||||
{% for vote in ups %}
|
{% for vote in ups %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a style="color:#{{vote.user.namecolor}};font-weight:bold" href="/@{{vote.user.username}}"><img loading="lazy" src="{{vote.user.profile_url}}" class="pp20"><span {% if vote.user.patron %}class="patron" style="background-color:#{{vote.user.namecolor}}"{% endif %}>{{vote.user.username}}</span></a></td>
|
<td><a style="color:#{{vote.user.namecolor}};font-weight:bold" href="/@{{vote.user.username}}"><img loading="lazy" src="{{vote.user.profile_url}}" class="pp20"><span {% if vote.user.patron %}class="patron" style="background-color:#{{vote.user.namecolor}}"{% endif %}>{{vote.user.username}}</span></a></td>
|
||||||
<td>{{vote.user.truecoins}}
|
<td>{{vote.user.truecoins}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>Downvotes</h2>
|
<h2>Downvotes</h2>
|
||||||
<div class="overflow-x-auto"><table class="table table-striped mb-5">
|
<div class="overflow-x-auto"><table class="table table-striped mb-5">
|
||||||
<thead class="bg-primary text-white"><tr><th>User</th></tr></thead>
|
<thead class="bg-primary text-white"><tr>
|
||||||
|
<th>User</th>
|
||||||
|
<th>User truescore</th>
|
||||||
|
</tr></thead>
|
||||||
|
|
||||||
{% for vote in downs %}
|
{% for vote in downs %}
|
||||||
<tr><td><a style="color:#{{vote.user.namecolor}}" href="/@{{vote.user.username}}"><img loading="lazy" src="{{vote.user.profile_url}}" class="pp20"><span {% if vote.user.patron %}class="patron" style="background-color:#{{vote.user.namecolor}}"{% endif %}>{{vote.user.username}}</span></a></td></tr>
|
<tr>
|
||||||
|
<td><a style="color:#{{vote.user.namecolor}};font-weight:bold" href="/@{{vote.user.username}}"><img loading="lazy" src="{{vote.user.profile_url}}" class="pp20"><span {% if vote.user.patron %}class="patron" style="background-color:#{{vote.user.namecolor}}"{% endif %}>{{vote.user.username}}</span></a></td>
|
||||||
|
<td>{{vote.user.truecoins}}</td>
|
||||||
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue