From a3af8de34b0ef0285f7b6e05f6cc93aef1d229e4 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:02:54 +1300 Subject: [PATCH] whack a mole --- app/activitypub/routes.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index f5f2dc0b..78419e45 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -509,17 +509,52 @@ def process_inbox_request(request_json, activitypublog_id, ip_address): elif request_json['object']['type'] == 'Page': # Editing a post post = Post.query.filter_by(ap_id=request_json['object']['id']).first() if post: - update_post_from_activity(post, request_json['object']) + try: + update_post_from_activity(post, request_json['object']) + except KeyError: + activity_log.result = 'exception' + db.session.commit() + return activity_log.result = 'success' else: activity_log.exception_message = 'Post not found' elif request_json['object']['type'] == 'Note': # Editing a reply reply = PostReply.query.filter_by(ap_id=request_json['object']['id']).first() if reply: - update_post_reply_from_activity(reply, request_json) + try: + update_post_reply_from_activity(reply, request_json['object']) + except KeyError: + activity_log.result = 'exception' + db.session.commit() + return activity_log.result = 'success' else: activity_log.exception_message = 'PostReply not found' + elif request_json['object']['type'] == 'Update': + if request_json['object']['object']['type'] == 'Page': + post = Post.query.filter_by(ap_id=request_json['object']['object']['id']).first() + if post: + try: + update_post_from_activity(post, request_json['object']) + except KeyError: + activity_log.result = 'exception' + db.session.commit() + return + activity_log.result = 'success' + else: + activity_log.exception_message = 'Post not found' + elif request_json['object']['object']['type'] == 'Note': + reply = PostReply.query.filter_by(ap_id=request_json['object']['object']['id']).first() + if reply: + try: + update_post_reply_from_activity(reply, request_json['object']) + except KeyError: + activity_log.result = 'exception' + db.session.commit() + return + activity_log.result = 'success' + else: + activity_log.exception_message = 'PostReply not found' else: activity_log.exception_message = 'Invalid type for Announce'