make sure stickied child comments are always at the top place they can be

pull/19/head
Aevann1 2022-11-26 06:01:20 +02:00
parent 0134302440
commit bcbf524fbe
2 changed files with 13 additions and 1 deletions

View File

@ -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()

View File

@ -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!"}