diff --git a/files/classes/comment.py b/files/classes/comment.py index 32f9b2733..e8939eb70 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -515,3 +515,16 @@ class Comment(Base): @lazy def is_effortpost(self): return len(self.body) >= 1000 + + def pin_parents(self): + c = self + while c.level > 2: + c = c.parent_comment + c.stickied_child_id = self.id + g.db.add(c) + + def unpin_parents(self): + cleanup = g.db.query(Comment).filter_by(stickied_child_id=self.id).all() + for c in cleanup: + c.stickied_child_id = None + g.db.add(c) diff --git a/files/routes/awards.py b/files/routes/awards.py index 0eb2b8dd8..cf092d803 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -316,10 +316,12 @@ def award_thing(v, thing_type, id): obj.stickied_utc += add else: obj.stickied_utc = int(time.time()) + add + if isinstance(obj, Comment): + obj.pin_parents() obj.stickied = f'{v.username}{PIN_AWARD_TEXT}' - if isinstance(obj. Post): + if isinstance(obj, Post): cache.delete_memoized(frontlist) elif kind == "unpin": if not obj.stickied_utc: abort(400) @@ -334,7 +336,10 @@ def award_thing(v, thing_type, id): if time.time() > t: obj.stickied = None obj.stickied_utc = None - cache.delete_memoized(frontlist) + if isinstance(obj, Post): + cache.delete_memoized(frontlist) + else: + obj.unpin_parents() else: obj.stickied_utc = t elif kind == "queen": if not author.queen: diff --git a/files/routes/comments.py b/files/routes/comments.py index a5d1eaee0..a92f5b96f 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -443,10 +443,13 @@ def delete_comment(cid, v): if c.author_id != v.id: abort(403) c.deleted_utc = int(time.time()) - c.stickied = None - c.stickied_utc = None g.db.add(c) + if c.stickied: + c.stickied = None + c.stickied_utc = None + c.unpin_parents() + if not (c.parent_post in ADMIGGER_THREADS and c.level == 1): v.comment_count -= 1 g.db.add(v) @@ -509,6 +512,8 @@ def pin_comment(cid, v): g.db.add(comment) + comment.pin_parents() + if v.id != comment.author_id: if comment.post.ghost: message = f"OP has pinned your [comment]({comment.shortlink})" else: message = f"@{v.username} (OP) has pinned your [comment]({comment.shortlink})" @@ -537,6 +542,8 @@ def unpin_comment(cid, v): comment.stickied_utc = None g.db.add(comment) + comment.unpin_parents() + if v.id != comment.author_id: message = f"@{v.username} (OP) has unpinned your [comment]({comment.shortlink})" send_repeatable_notification(comment.author_id, message) diff --git a/files/routes/holes.py b/files/routes/holes.py index bd7e80ab0..0a55a0b31 100644 --- a/files/routes/holes.py +++ b/files/routes/holes.py @@ -852,6 +852,8 @@ def pin_comment_mod(cid, v): g.db.add(comment) + comment.pin_parents() + ma = HoleAction( hole=comment.post.hole, kind="pin_comment", @@ -883,6 +885,8 @@ def unpin_comment_mod(cid, v): comment.stickied_utc = None g.db.add(comment) + comment.unpin_parents() + ma = HoleAction( hole=comment.post.hole, kind="unpin_comment",