fix issue that made it so when u unpin a child comment, if theres another child comment in the same chain, it gets effectively unpinned as well

pull/219/head
Aevann 2023-12-04 15:41:42 +02:00
parent a7ed2707d0
commit aeb3f76e7b
2 changed files with 14 additions and 6 deletions

View File

@ -187,7 +187,7 @@ class Comment(Base):
is_bot = Column(Boolean, default=False)
stickied = Column(String)
stickied_utc = Column(Integer)
stickied_child_id = Column(Integer)
num_of_pinned_children = Column(Integer, default=0)
sentto = Column(Integer, ForeignKey("users.id"))
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
upvotes = Column(Integer, default=1)
@ -279,7 +279,7 @@ class Comment(Base):
if self.replies2 != None:
return self.replies2
replies = g.db.query(Comment).filter_by(parent_comment_id=self.id).order_by(Comment.stickied, Comment.stickied_child_id)
replies = g.db.query(Comment).filter_by(parent_comment_id=self.id).order_by(Comment.stickied, Comment.num_of_pinned_children.desc())
if not self.parent_post: sort='old'
return sort_objects(sort, replies, Comment).all()
@ -520,11 +520,14 @@ class Comment(Base):
c = self
while c.level > 2:
c = c.parent_comment
c.stickied_child_id = self.id
c.num_of_pinned_children += 1
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
c = self
while c.level > 2:
c = c.parent_comment
c.num_of_pinned_children -= 1
if c.num_of_pinned_children < 0:
c.num_of_pinned_children = 0
g.db.add(c)

View File

@ -0,0 +1,5 @@
alter table comments add column num_of_pinned_children int default 0 not null;
update comments set num_of_pinned_children=1 where stickied_child_id is not null;
alter table comments alter column num_of_pinned_children drop default;
alter table comments drop column stickied_child_id;