mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
Check if object already exists for Create activity too #216
This commit is contained in:
parent
f06a299f56
commit
2f6e60ac40
1 changed files with 50 additions and 38 deletions
|
@ -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:
|
||||||
|
|
Loading…
Add table
Reference in a new issue