make sure stickied child comments are always at the top place they can be
parent
0134302440
commit
bcbf524fbe
|
@ -49,6 +49,7 @@ class Comment(Base):
|
||||||
is_bot = Column(Boolean, default=False)
|
is_bot = Column(Boolean, default=False)
|
||||||
stickied = Column(String)
|
stickied = Column(String)
|
||||||
stickied_utc = Column(Integer)
|
stickied_utc = Column(Integer)
|
||||||
|
stickied_child_id = Column(Integer)
|
||||||
sentto = Column(Integer, ForeignKey("users.id"))
|
sentto = Column(Integer, ForeignKey("users.id"))
|
||||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||||
upvotes = Column(Integer, default=1)
|
upvotes = Column(Integer, default=1)
|
||||||
|
@ -139,7 +140,7 @@ class Comment(Base):
|
||||||
if self.replies2 != None:
|
if self.replies2 != None:
|
||||||
return self.replies2
|
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'
|
if not self.parent_submission: sort='old'
|
||||||
return sort_objects(sort, replies, Comment,
|
return sort_objects(sort, replies, Comment,
|
||||||
include_shadowbanned=(v and v.can_see_shadowbanned)).all()
|
include_shadowbanned=(v and v.can_see_shadowbanned)).all()
|
||||||
|
|
|
@ -1334,6 +1334,12 @@ def sticky_comment(cid, v):
|
||||||
message = f"@{v.username} (Admin) has pinned your [comment]({comment.shortlink})"
|
message = f"@{v.username} (Admin) has pinned your [comment]({comment.shortlink})"
|
||||||
send_repeatable_notification(comment.author_id, message)
|
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!"}
|
return {"message": "Comment pinned!"}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1359,6 +1365,11 @@ def unsticky_comment(cid, v):
|
||||||
message = f"@{v.username} (Admin) has unpinned your [comment]({comment.shortlink})"
|
message = f"@{v.username} (Admin) has unpinned your [comment]({comment.shortlink})"
|
||||||
send_repeatable_notification(comment.author_id, message)
|
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!"}
|
return {"message": "Comment unpinned!"}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue