mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 11:51:27 -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,18 +575,21 @@ 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 = Post.query.filter_by(ap_id=request_json['object']['id']).first()
|
||||||
post = None
|
|
||||||
else:
|
|
||||||
post = Post.query.filter_by(ap_id=request_json['object']['id']).first()
|
|
||||||
if post:
|
if post:
|
||||||
activity_log.activity_type = 'Update'
|
if request_json['type'] == 'Create':
|
||||||
if can_edit(request_json['actor'], post):
|
activity_log.result = 'ignored'
|
||||||
update_post_from_activity(post, request_json)
|
activity_log.exception_message = 'Create received for already known object'
|
||||||
announce_activity_to_followers(post.community, post.author, request_json)
|
db.session.commit()
|
||||||
activity_log.result = 'success'
|
return
|
||||||
else:
|
else:
|
||||||
activity_log.exception_message = 'Edit attempt denied'
|
activity_log.activity_type = 'Update'
|
||||||
|
if can_edit(request_json['actor'], post):
|
||||||
|
update_post_from_activity(post, request_json)
|
||||||
|
announce_activity_to_followers(post.community, post.author, request_json)
|
||||||
|
activity_log.result = 'success'
|
||||||
|
else:
|
||||||
|
activity_log.exception_message = 'Edit attempt denied'
|
||||||
else:
|
else:
|
||||||
if can_create_post(user, community):
|
if can_create_post(user, community):
|
||||||
try:
|
try:
|
||||||
|
@ -600,18 +603,21 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
|
||||||
else:
|
else:
|
||||||
post = None
|
post = None
|
||||||
else:
|
else:
|
||||||
if request_json['type'] == 'Create':
|
reply = PostReply.query.filter_by(ap_id=request_json['object']['id']).first()
|
||||||
reply = None
|
|
||||||
else:
|
|
||||||
reply = PostReply.query.filter_by(ap_id=request_json['object']['id']).first()
|
|
||||||
if reply:
|
if reply:
|
||||||
activity_log.activity_type = 'Update'
|
if request_json['type'] == 'Create':
|
||||||
if can_edit(request_json['actor'], reply):
|
activity_log.result = 'ignored'
|
||||||
update_post_reply_from_activity(reply, request_json)
|
activity_log.exception_message = 'Create received for already known object'
|
||||||
announce_activity_to_followers(reply.community, reply.author, request_json)
|
db.session.commit()
|
||||||
activity_log.result = 'success'
|
return
|
||||||
else:
|
else:
|
||||||
activity_log.exception_message = 'Edit attempt denied'
|
activity_log.activity_type = 'Update'
|
||||||
|
if can_edit(request_json['actor'], reply):
|
||||||
|
update_post_reply_from_activity(reply, request_json)
|
||||||
|
announce_activity_to_followers(reply.community, reply.author, request_json)
|
||||||
|
activity_log.result = 'success'
|
||||||
|
else:
|
||||||
|
activity_log.exception_message = 'Edit attempt denied'
|
||||||
else:
|
else:
|
||||||
if can_create_post_reply(user, community):
|
if can_create_post_reply(user, community):
|
||||||
try:
|
try:
|
||||||
|
@ -678,36 +684,42 @@ 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 = Post.query.filter_by(ap_id=request_json['object']['object']['id']).first()
|
||||||
post = None
|
|
||||||
else:
|
|
||||||
post = Post.query.filter_by(ap_id=request_json['object']['object']['id']).first()
|
|
||||||
if post:
|
if post:
|
||||||
try:
|
if request_json['object']['type'] == 'Create':
|
||||||
update_post_from_activity(post, request_json['object'])
|
activity_log.result = 'ignored'
|
||||||
except KeyError:
|
activity_log.exception_message = 'Create received for already known object'
|
||||||
activity_log.result = 'exception'
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return
|
return
|
||||||
activity_log.result = 'success'
|
else:
|
||||||
|
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 was a Create, or an Update sent instead of a Create
|
else: # activity was a Create, or an Update sent instead of a Create
|
||||||
if can_create_post(user, community):
|
if can_create_post(user, community):
|
||||||
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:
|
else:
|
||||||
if request_json['object']['type'] == 'Create':
|
reply = PostReply.query.filter_by(ap_id=request_json['object']['object']['id']).first()
|
||||||
reply = None
|
|
||||||
else:
|
|
||||||
reply = PostReply.query.filter_by(ap_id=request_json['object']['object']['id']).first()
|
|
||||||
if reply:
|
if reply:
|
||||||
try:
|
if request_json['object']['type'] == 'Create':
|
||||||
update_post_reply_from_activity(reply, request_json['object'])
|
activity_log.result = 'ignored'
|
||||||
except KeyError:
|
activity_log.exception_message = 'Create received for already known object'
|
||||||
activity_log.result = 'exception'
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return
|
return
|
||||||
activity_log.result = 'success'
|
else:
|
||||||
|
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 was a Create, or an Update sent instead of a Create
|
else: # activity was a Create, or an Update sent instead of a Create
|
||||||
if can_create_post_reply(user, community):
|
if can_create_post_reply(user, community):
|
||||||
post = create_post_reply(activity_log, community, in_reply_to, request_json['object'], user, announce_id=request_json['id'])
|
post = create_post_reply(activity_log, community, in_reply_to, request_json['object'], user, announce_id=request_json['id'])
|
||||||
|
|
Loading…
Add table
Reference in a new issue