update post counts when deletion happens

This commit is contained in:
rimu 2024-01-05 10:36:55 +13:00
parent 4f2ac1b89f
commit c5da11335b
2 changed files with 11 additions and 2 deletions

View file

@ -504,8 +504,12 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
user_ap_id = request_json['object']['actor'] user_ap_id = request_json['object']['actor']
community_ap_id = request_json['object']['audience'] if 'audience' in request_json['object'] else request_json['actor'] community_ap_id = request_json['object']['audience'] if 'audience' in request_json['object'] else request_json['actor']
to_be_deleted_ap_id = request_json['object']['object'] to_be_deleted_ap_id = request_json['object']['object']
delete_post_or_comment(user_ap_id, community_ap_id, to_be_deleted_ap_id) if isinstance(to_be_deleted_ap_id, dict):
activity_log.result = 'success' activity_log.result = 'failure'
activity_log.exception_message = 'dict instead of string ' + str(to_be_deleted_ap_id)
else:
delete_post_or_comment(user_ap_id, community_ap_id, to_be_deleted_ap_id)
activity_log.result = 'success'
elif request_json['object']['type'] == 'Page': # Editing a post elif request_json['object']['type'] == 'Page': # Editing a post
post = Post.query.filter_by(ap_id=request_json['object']['id']).first() post = Post.query.filter_by(ap_id=request_json['object']['id']).first()
if post: if post:
@ -685,12 +689,14 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
post = Post.query.filter_by(ap_id=ap_id).first() post = Post.query.filter_by(ap_id=ap_id).first()
if post: if post:
post.delete_dependencies() post.delete_dependencies()
post.community.post_count -= 1
db.session.delete(post) db.session.delete(post)
else: else:
reply = PostReply.query.filter_by(ap_id=ap_id).first() reply = PostReply.query.filter_by(ap_id=ap_id).first()
if reply: if reply:
reply.body_html = '<p><em>deleted</em></p>' reply.body_html = '<p><em>deleted</em></p>'
reply.body = 'deleted' reply.body = 'deleted'
reply.post.reply_count -= 1
db.session.commit() db.session.commit()
activity_log.result = 'success' activity_log.result = 'success'
elif request_json['type'] == 'Like': # Upvote elif request_json['type'] == 'Like': # Upvote

View file

@ -856,15 +856,18 @@ def delete_post_or_comment_task(user_ap_id, community_ap_id, to_be_deleted_ap_id
to_delete.delete_dependencies() to_delete.delete_dependencies()
to_delete.flush_cache() to_delete.flush_cache()
db.session.delete(to_delete) db.session.delete(to_delete)
community.post_count -= 1
db.session.commit() db.session.commit()
elif isinstance(to_delete, PostReply): elif isinstance(to_delete, PostReply):
to_delete.post.flush_cache() to_delete.post.flush_cache()
to_delete.post.reply_count -= 1
if to_delete.has_replies(): if to_delete.has_replies():
to_delete.body = 'Deleted by author' if to_delete.author.id == deletor.id else 'Deleted by moderator' to_delete.body = 'Deleted by author' if to_delete.author.id == deletor.id else 'Deleted by moderator'
to_delete.body_html = markdown_to_html(to_delete.body) to_delete.body_html = markdown_to_html(to_delete.body)
else: else:
to_delete.delete_dependencies() to_delete.delete_dependencies()
db.session.delete(to_delete) db.session.delete(to_delete)
db.session.commit() db.session.commit()