[themotte/rDrama#451] define comment_on_unpublish() function

This commit is contained in:
faul_sname 2023-01-03 01:14:58 -08:00
parent 2e0104a7cc
commit f8c27f3620

View file

@ -67,3 +67,17 @@ def comment_on_unpublish(comment:Comment):
Should be used to update stateful counters, notifications, etc. that
reflect the comments users will actually see.
"""
author = comment.author
# Comment counter for parent submission
comment.post.comment_count -= 1
g.db.add(comment.post)
# Comment counter for author's profile
comment.author.comment_count = g.db.query(Comment).filter(
Comment.author_id == comment.author_id,
Comment.parent_submission != None,
Comment.is_banned == False,
Comment.deleted_utc == 0,
).count()
g.db.add(comment.author)