refactor pinning child comments

master
Aevann1 2022-09-01 22:31:08 +02:00
parent 6b6a3163a5
commit 17fd089870
2 changed files with 12 additions and 1 deletions

View File

@ -69,8 +69,9 @@ class Comment(Base):
post = relationship("Submission", back_populates="comments")
author = relationship("User", primaryjoin="User.id==Comment.author_id")
senttouser = relationship("User", primaryjoin="User.id==Comment.sentto")
top_comment = relationship("Comment", primaryjoin="Comment.id==Comment.top_comment_id")
parent_comment = relationship("Comment", remote_side=[id], back_populates="child_comments")
child_comments = relationship("Comment", order_by="Comment.realupvotes.desc()", remote_side=[parent_comment_id], back_populates="parent_comment")
child_comments = relationship("Comment", order_by="Comment.stickied, Comment.realupvotes.desc()", remote_side=[parent_comment_id], back_populates="parent_comment")
awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="comment")
flags = relationship("CommentFlag", order_by="CommentFlag.created_utc")
options = relationship("CommentOption", order_by="CommentOption.id")

View File

@ -171,6 +171,11 @@ def post_id(pid, anything=None, v=None, sub=None):
output.append(comment)
pinned = [c[0] for c in comments.filter(Comment.stickied != None).all()]
for x in pinned:
if x.level > 1:
pinned.remove(x)
pinned.append(x.top_comment)
comments = comments.filter(Comment.level == 1, Comment.stickied == None)
@ -182,6 +187,11 @@ def post_id(pid, anything=None, v=None, sub=None):
else:
pinned = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.stickied != None).all()
for x in pinned:
if x.level > 1:
pinned.remove(x)
pinned.append(x.top_comment)
comments = g.db.query(Comment).join(Comment.author).filter(User.shadowbanned == None, Comment.parent_submission == post.id, Comment.level == 1, Comment.stickied == None)
comments = sort_comments(sort, comments)