From 645470f12a3fa0f7fb90f0dc4a039df53deb8595 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 26 Nov 2022 06:01:20 +0200 Subject: [PATCH] make sure stickied child comments are always at the top place they can be --- files/classes/comment.py | 3 ++- files/routes/admin.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 5972622d3..205ede4e1 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -49,6 +49,7 @@ class Comment(Base): is_bot = Column(Boolean, default=False) stickied = Column(String) stickied_utc = Column(Integer) + stickied_child_id = Column(Integer) sentto = Column(Integer, ForeignKey("users.id")) app_id = Column(Integer, ForeignKey("oauth_apps.id")) upvotes = Column(Integer, default=1) @@ -139,7 +140,7 @@ class Comment(Base): if self.replies2 != None: return self.replies2 - replies = db.query(Comment).filter_by(parent_comment_id=self.id).order_by(Comment.stickied) + replies = db.query(Comment).filter_by(parent_comment_id=self.id).order_by(Comment.stickied, Comment.stickied_child_id) if not self.parent_submission: sort='old' return sort_objects(sort, replies, Comment, include_shadowbanned=(v and v.can_see_shadowbanned)).all() diff --git a/files/routes/admin.py b/files/routes/admin.py index 7d5c45b1b..5f61361fb 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1334,6 +1334,12 @@ def sticky_comment(cid, v): message = f"@{v.username} (Admin) has pinned your [comment]({comment.shortlink})" send_repeatable_notification(comment.author_id, message) + c = comment + while c.level > 2: + c = c.parent_comment + c.stickied_child_id = comment.id + g.db.add(c) + return {"message": "Comment pinned!"} @@ -1359,6 +1365,11 @@ def unsticky_comment(cid, v): message = f"@{v.username} (Admin) has unpinned your [comment]({comment.shortlink})" send_repeatable_notification(comment.author_id, message) + cleanup = g.db.query(Comment).filter_by(stickied_child_id=comment.id).all() + for c in cleanup: + c.stickied_child_id = None + g.db.add(c) + return {"message": "Comment unpinned!"}