consistent behavior for pinning child comments
parent
ad9a444f30
commit
2aa9c45ee5
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue