mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Discourse follow community #111
This commit is contained in:
parent
f3c4e55223
commit
1c2be79dab
2 changed files with 22 additions and 30 deletions
|
@ -1277,19 +1277,27 @@ def user_inbox(actor):
|
|||
return shared_inbox()
|
||||
try:
|
||||
HttpSignature.verify_request(request, actor.public_key, skip_date=True)
|
||||
if 'type' in request_json and request_json['type'] == 'Follow':
|
||||
if current_app.debug:
|
||||
process_user_follow_request(request_json, activity_log.id, actor.id)
|
||||
else:
|
||||
process_user_follow_request.delay(request_json, activity_log.id, actor.id)
|
||||
return ''
|
||||
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 ''
|
||||
if 'type' in request_json:
|
||||
if request_json['type'] == 'Follow':
|
||||
if current_app.debug:
|
||||
process_user_follow_request(request_json, activity_log.id, actor.id)
|
||||
else:
|
||||
process_user_follow_request.delay(request_json, activity_log.id, actor.id)
|
||||
elif request_json['type'] == 'Undo' and 'object' in request_json and request_json['object']['type'] == 'Follow':
|
||||
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(actor.id)
|
||||
if local_user:
|
||||
db.session.query(UserFollower).filter_by(local_user_id=local_user.id, remote_user_id=remote_user.id, is_accepted=True).delete()
|
||||
activity_log.result = 'success'
|
||||
else:
|
||||
activity_log.exception_message = 'Could not find local user'
|
||||
activity_log.result = 'failure'
|
||||
db.session.commit()
|
||||
elif request_json['type'] == 'Accept' or request_json['type'] == 'Reject':
|
||||
if request_json['object']['type'] == 'Follow':
|
||||
return shared_inbox()
|
||||
|
||||
except VerificationError:
|
||||
activity_log.result = 'failure'
|
||||
activity_log.exception_message = 'Could not verify signature'
|
||||
|
@ -1349,22 +1357,6 @@ def process_user_follow_request(request_json, activitypublog_id, remote_user_id)
|
|||
db.session.commit()
|
||||
|
||||
|
||||
@celery.task
|
||||
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, is_accepted=True).delete()
|
||||
activity_log.result = 'success'
|
||||
else:
|
||||
activity_log.exception_message = 'Could not find local user'
|
||||
activity_log.result = 'failure'
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@bp.route('/c/<actor>/inbox', methods=['GET', 'POST'])
|
||||
def community_inbox(actor):
|
||||
return shared_inbox()
|
||||
|
|
|
@ -172,7 +172,7 @@ class RsaKeys:
|
|||
return private_key_serialized, public_key_serialized
|
||||
|
||||
|
||||
# Signatures
|
||||
# Get a piece of the signature string. Similar to parse_signature except unencumbered by needing to return a HttpSignatureDetails
|
||||
def signature_part(signature, key):
|
||||
parts = signature.split(',')
|
||||
for part in parts:
|
||||
|
|
Loading…
Add table
Reference in a new issue