From c5da11335bb61f9d6414aadc304d974489b0a7cc Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:36:55 +1300 Subject: [PATCH] update post counts when deletion happens --- app/activitypub/routes.py | 10 ++++++++-- app/activitypub/util.py | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index 1f65f15a..fe98cef6 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -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 = '
deleted
' reply.body = 'deleted' + reply.post.reply_count -= 1 db.session.commit() activity_log.result = 'success' elif request_json['type'] == 'Like': # Upvote diff --git a/app/activitypub/util.py b/app/activitypub/util.py index fa0fb86c..450edf59 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -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()