mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
update post counts when deletion happens
This commit is contained in:
parent
4f2ac1b89f
commit
c5da11335b
2 changed files with 11 additions and 2 deletions
|
@ -504,8 +504,12 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
|||
user_ap_id = request_json['object']['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']
|
||||
delete_post_or_comment(user_ap_id, community_ap_id, to_be_deleted_ap_id)
|
||||
activity_log.result = 'success'
|
||||
if isinstance(to_be_deleted_ap_id, dict):
|
||||
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
|
||||
post = Post.query.filter_by(ap_id=request_json['object']['id']).first()
|
||||
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()
|
||||
if post:
|
||||
post.delete_dependencies()
|
||||
post.community.post_count -= 1
|
||||
db.session.delete(post)
|
||||
else:
|
||||
reply = PostReply.query.filter_by(ap_id=ap_id).first()
|
||||
if reply:
|
||||
reply.body_html = '<p><em>deleted</em></p>'
|
||||
reply.body = 'deleted'
|
||||
reply.post.reply_count -= 1
|
||||
db.session.commit()
|
||||
activity_log.result = 'success'
|
||||
elif request_json['type'] == 'Like': # Upvote
|
||||
|
|
|
@ -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.flush_cache()
|
||||
db.session.delete(to_delete)
|
||||
community.post_count -= 1
|
||||
db.session.commit()
|
||||
elif isinstance(to_delete, PostReply):
|
||||
to_delete.post.flush_cache()
|
||||
to_delete.post.reply_count -= 1
|
||||
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_html = markdown_to_html(to_delete.body)
|
||||
else:
|
||||
to_delete.delete_dependencies()
|
||||
db.session.delete(to_delete)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue