Process Undo/Follow requests from remote actors to local actors

This commit is contained in:
freamon 2024-04-29 17:13:15 +01:00
parent f7cfd1f92b
commit d2a99e08b4

View file

@ -1217,7 +1217,13 @@ def user_inbox(actor):
else:
process_user_follow_request.delay(request_json, activity_log.id, actor.id)
return ''
# todo: undo/follow
if ('type' in request_json and request_json['type'] == 'Undo' and
'object' in request_json and request_json['object']['type'] == 'Follow'):
if current_app.debug:
process_user_undo_follow_request(request_json, activity_log.id, actor.id)
else:
process_user_undo_follow_request.delay(request_json, activity_log.id, actor.id)
return ''
except VerificationError:
activity_log.result = 'failure'
activity_log.exception_message = 'Could not verify signature'
@ -1271,6 +1277,17 @@ def process_user_follow_request(request_json, activitypublog_id, remote_user_id)
db.session.commit()
def process_user_undo_follow_request(request_json, activitypublog_id, remote_user_id):
activity_log = ActivityPubLog.query.get(activitypublog_id)
local_user_ap_id = request_json['object']['object']
local_user = find_actor_or_create(local_user_ap_id, create_if_not_found=False)
remote_user = User.query.get(remote_user_id)
if local_user:
db.session.query(UserFollower).filter_by(local_user_id=local_user.id, remote_user_id=remote_user.id).delete()
activity_log.result = 'success'
db.session.commit()
@bp.route('/c/<actor>/inbox', methods=['GET', 'POST'])
def community_inbox(actor):
return shared_inbox()