remotes/1693045480750635534/spooky-22
Aevann1 2021-08-31 18:23:34 +02:00
parent fd797e1486
commit e0da13397f
4 changed files with 60 additions and 47 deletions

View File

@ -350,7 +350,19 @@ class User(Base, Stndrd, Age_times):
return self.notifications.filter(Notification.read == False).join(Notification.comment).filter(
Comment.author_id == AUTOJANNY_ACCOUNT).count()
def notification_subscriptions(self, page=1, all_=False):
@cache.memoize()
def notification_messages(self, page=1):
if self.admin_level == 6: comments = g.db.query(Comment).filter(or_(Comment.author_id==self.id, Comment.sentto==self.id, Comment.sentto==0)).filter(Comment.parent_submission == None).order_by(Comment.created_utc.desc()).limit(200).all()
else: comments = g.db.query(Comment).filter(or_(Comment.author_id==self.id, Comment.sentto==self.id)).filter(Comment.parent_submission == None).order_by(Comment.created_utc.desc()).limit(200).all()
comments = [c for c in comments if c.child_comments == []]
firstrange = 25 * (page - 1)
secondrange = firstrange + 26
comments = comments[firstrange:secondrange]
def notification_subscriptions(self, page=1):
notifications = self.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT)
@ -368,7 +380,7 @@ class User(Base, Stndrd, Age_times):
return output
def notification_commentlisting(self, page=1, all_=False):
def notification_commentlisting(self, page=1):
notifications = self.notifications.join(Notification.comment).filter(
Comment.is_banned == False,

View File

@ -182,3 +182,4 @@ def send_admin(vid, text):
for admin in admins:
notif = Notification(comment_id=new_comment.id, user_id=admin.id)
g.db.add(notif)
cache.delete_memoized(User.notification_messages, admin)

View File

@ -21,23 +21,18 @@ def notifications(v):
messages = request.args.get('messages', False)
posts = request.args.get('posts', False)
if messages:
if v.admin_level == 6: comments = g.db.query(Comment).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id, Comment.sentto==0)).filter(Comment.parent_submission == None).order_by(Comment.created_utc.desc()).limit(200).all()
else: comments = g.db.query(Comment).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id)).filter(Comment.parent_submission == None).order_by(Comment.created_utc.desc()).limit(200).all()
comments = [c for c in comments if c.child_comments == []]
cids = v.notification_messages(page=page)
firstrange = 25 * (page - 1)
secondrange = firstrange + 26
comments = comments[firstrange:secondrange]
next_exists = (len(comments) == 26)
comments = comments[:25]
elif posts:
cids = v.notification_subscriptions(page=page, all_=all_)
cids = v.notification_subscriptions(page=page)
next_exists = (len(cids) == 26)
cids = cids[:25]
comments = get_comments(cids, v=v)
else:
cids = v.notification_commentlisting(page=page, all_=all_)
cids = v.notification_commentlisting(page=page)
next_exists = (len(cids) == 26)
cids = cids[:25]
comments = get_comments(cids, v=v, load_parent=True)

View File

@ -95,43 +95,6 @@ def get_profilecss(username):
resp.headers.add("Content-Type", "text/css")
return resp
@app.post("/@<username>/reply/<id>")
@auth_required
def messagereply(v, username, id):
message = request.form.get("message", "")[:1000].strip()
user = get_user(username)
message = message.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
# check existing
existing = g.db.query(Comment).join(CommentAux).filter(Comment.author_id == v.id,
Comment.sentto == user.id,
CommentAux.body == message,
).options(contains_eager(Comment.comment_aux)).first()
if existing:
if existing.parent_comment_id: return redirect(f'/notifications?messages=true#comment-{existing.parent_comment_id}')
else: return redirect(f'/notifications?messages=true#comment-{existing.id}')
with CustomRenderer() as renderer: text_html = renderer.render(mistletoe.Document(message))
text_html = sanitize(text_html)
parent = get_comment(int(id), v=v)
new_comment = Comment(author_id=v.id,
parent_submission=None,
parent_comment_id=id,
level=parent.level + 1,
sentto=user.id
)
g.db.add(new_comment)
g.db.flush()
new_aux = CommentAux(id=new_comment.id, body=message, body_html=text_html)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, user_id=user.id)
g.db.add(notif)
if not request.referrer or request.referrer.endswith('/notifications'): return redirect(f"/notifications?all=true#comment-{id}")
else: return redirect(f"{request.referrer}#comment-{id}")
@app.get("/songs/<id>")
def songs(id):
try: id = int(id)
@ -181,6 +144,8 @@ def message2(v, username):
send_pm(v.id, user, message)
cache.delete_memoized(User.notification_messages, user)
try:
beams_client.publish_to_interests(
interests=[str(user.id)],
@ -199,6 +164,46 @@ def message2(v, username):
return redirect(f"/@{username}")
@app.post("/@<username>/reply/<id>")
@auth_required
def messagereply(v, username, id):
message = request.form.get("message", "")[:1000].strip()
user = get_user(username)
message = message.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
# check existing
existing = g.db.query(Comment).join(CommentAux).filter(Comment.author_id == v.id,
Comment.sentto == user.id,
CommentAux.body == message,
).options(contains_eager(Comment.comment_aux)).first()
if existing:
if existing.parent_comment_id: return redirect(f'/notifications?messages=true#comment-{existing.parent_comment_id}')
else: return redirect(f'/notifications?messages=true#comment-{existing.id}')
with CustomRenderer() as renderer: text_html = renderer.render(mistletoe.Document(message))
text_html = sanitize(text_html)
parent = get_comment(int(id), v=v)
new_comment = Comment(author_id=v.id,
parent_submission=None,
parent_comment_id=id,
level=parent.level + 1,
sentto=user.id
)
g.db.add(new_comment)
g.db.flush()
new_aux = CommentAux(id=new_comment.id, body=message, body_html=text_html)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, user_id=user.id)
g.db.add(notif)
cache.delete_memoized(User.notification_messages, user)
if not request.referrer or request.referrer.endswith('/notifications'): return redirect(f"/notifications?all=true#comment-{id}")
else: return redirect(f"{request.referrer}#comment-{id}")
@app.get("/2faqr/<secret>")
@auth_required
def mfa_qr(secret, v):