mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
apf part 10: Accepts for follows
This commit is contained in:
parent
3d053ae70a
commit
3cc411f512
2 changed files with 30 additions and 4 deletions
|
@ -585,6 +585,32 @@ def process_inbox_request(request_json, store_ap_json):
|
|||
log_incoming_ap(request_json['id'], APLOG_FOLLOW, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
return
|
||||
|
||||
# Accept: remote server is accepting our previous follow request
|
||||
if request_json['type'] == 'Accept':
|
||||
user = None
|
||||
if isinstance(request_json['object'], str): # a.gup.pe accepts using a string with the ID of the follow request
|
||||
join_request_parts = request_json['object'].split('/')
|
||||
join_request = CommunityJoinRequest.query.get(join_request_parts[-1])
|
||||
if join_request:
|
||||
user = User.query.get(join_request.user_id)
|
||||
elif request_json['object']['type'] == 'Follow':
|
||||
user_ap_id = request_json['object']['actor']
|
||||
user = find_actor_or_create(user_ap_id, create_if_not_found=False)
|
||||
if not user:
|
||||
log_incoming_ap(request_json['id'], APLOG_ACCEPT, APLOG_FAILURE, request_json if store_ap_json else None, 'Could not find recipient of Accept')
|
||||
return
|
||||
join_request = CommunityJoinRequest.query.filter_by(user_id=user.id, community_id=community.id).first()
|
||||
if join_request:
|
||||
existing_membership = CommunityMember.query.filter_by(user_id=join_request.user_id, community_id=join_request.community_id).first()
|
||||
if not existing_membership:
|
||||
member = CommunityMember(user_id=join_request.user_id, community_id=join_request.community_id)
|
||||
db.session.add(member)
|
||||
community.subscriptions_count += 1
|
||||
db.session.commit()
|
||||
cache.delete_memoized(community_membership, user, community)
|
||||
log_incoming_ap(request_json['id'], APLOG_ACCEPT, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -435,6 +435,10 @@ def do_subscribe(actor, user_id, admin_preload=False):
|
|||
else:
|
||||
pre_load_message['community_banned_by_local_instance'] = True
|
||||
success = True
|
||||
# for local communities, joining is instant
|
||||
member = CommunityMember(user_id=user.id, community_id=community.id)
|
||||
db.session.add(member)
|
||||
db.session.commit()
|
||||
if remote:
|
||||
# send ActivityPub message to remote community, asking to follow. Accept message will be sent to our shared inbox
|
||||
join_request = CommunityJoinRequest(user_id=user.id, community_id=community.id)
|
||||
|
@ -464,10 +468,6 @@ def do_subscribe(actor, user_id, admin_preload=False):
|
|||
else:
|
||||
pre_load_message['status'] = msg_to_user
|
||||
|
||||
# for local communities, joining is instant
|
||||
member = CommunityMember(user_id=user.id, community_id=community.id)
|
||||
db.session.add(member)
|
||||
db.session.commit()
|
||||
if success is True:
|
||||
if not admin_preload:
|
||||
flash('You joined ' + community.title)
|
||||
|
|
Loading…
Add table
Reference in a new issue