diff --git a/files/classes/comment.py b/files/classes/comment.py index 4f241a284..6cb92acb4 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -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") diff --git a/files/routes/posts.py b/files/routes/posts.py index 82dcdd231..42d123461 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -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)