Check if object already exists for Create activity too #216

This commit is contained in:
freamon 2024-06-25 17:23:10 +01:00
parent f06a299f56
commit 2f6e60ac40

View file

@ -575,11 +575,14 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
if object_type in new_content_types: # create or update a post if object_type in new_content_types: # create or update a post
in_reply_to = request_json['object']['inReplyTo'] if 'inReplyTo' in request_json['object'] else None in_reply_to = request_json['object']['inReplyTo'] if 'inReplyTo' in request_json['object'] else None
if not in_reply_to: if not in_reply_to:
if request_json['type'] == 'Create':
post = None
else:
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:
if request_json['type'] == 'Create':
activity_log.result = 'ignored'
activity_log.exception_message = 'Create received for already known object'
db.session.commit()
return
else:
activity_log.activity_type = 'Update' activity_log.activity_type = 'Update'
if can_edit(request_json['actor'], post): if can_edit(request_json['actor'], post):
update_post_from_activity(post, request_json) update_post_from_activity(post, request_json)
@ -599,12 +602,15 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
post = None post = None
else: else:
post = None post = None
else:
if request_json['type'] == 'Create':
reply = None
else: else:
reply = PostReply.query.filter_by(ap_id=request_json['object']['id']).first() reply = PostReply.query.filter_by(ap_id=request_json['object']['id']).first()
if reply: if reply:
if request_json['type'] == 'Create':
activity_log.result = 'ignored'
activity_log.exception_message = 'Create received for already known object'
db.session.commit()
return
else:
activity_log.activity_type = 'Update' activity_log.activity_type = 'Update'
if can_edit(request_json['actor'], reply): if can_edit(request_json['actor'], reply):
update_post_reply_from_activity(reply, request_json) update_post_reply_from_activity(reply, request_json)
@ -678,11 +684,14 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
in_reply_to = request_json['object']['object']['inReplyTo'] if 'inReplyTo' in \ in_reply_to = request_json['object']['object']['inReplyTo'] if 'inReplyTo' in \
request_json['object']['object'] else None request_json['object']['object'] else None
if not in_reply_to: if not in_reply_to:
if request_json['object']['type'] == 'Create':
post = None
else:
post = Post.query.filter_by(ap_id=request_json['object']['object']['id']).first() post = Post.query.filter_by(ap_id=request_json['object']['object']['id']).first()
if post: if post:
if request_json['object']['type'] == 'Create':
activity_log.result = 'ignored'
activity_log.exception_message = 'Create received for already known object'
db.session.commit()
return
else:
try: try:
update_post_from_activity(post, request_json['object']) update_post_from_activity(post, request_json['object'])
except KeyError: except KeyError:
@ -695,12 +704,15 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
post = create_post(activity_log, community, request_json['object'], user, announce_id=request_json['id']) post = create_post(activity_log, community, request_json['object'], user, announce_id=request_json['id'])
else: else:
post = None post = None
else:
if request_json['object']['type'] == 'Create':
reply = None
else: else:
reply = PostReply.query.filter_by(ap_id=request_json['object']['object']['id']).first() reply = PostReply.query.filter_by(ap_id=request_json['object']['object']['id']).first()
if reply: if reply:
if request_json['object']['type'] == 'Create':
activity_log.result = 'ignored'
activity_log.exception_message = 'Create received for already known object'
db.session.commit()
return
else:
try: try:
update_post_reply_from_activity(reply, request_json['object']) update_post_reply_from_activity(reply, request_json['object'])
except KeyError: except KeyError: