From 1907c009b330c06c01f041e8d774fd7872b975fd Mon Sep 17 00:00:00 2001 From: freamon Date: Tue, 20 Aug 2024 21:39:53 +0000 Subject: [PATCH] Also for settings import - Don't send subscription activity to communities on dead instances --- app/user/routes.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/user/routes.py b/app/user/routes.py index afbc41ef..55efe891 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -731,15 +731,19 @@ def import_settings_task(user_id, filename): # 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) db.session.add(join_request) + member = CommunityMember(user_id=user.id, community_id=community.id) + db.session.add(member) db.session.commit() - follow = { - "actor": current_user.public_url(), - "to": [community.public_url()], - "object": community.public_url(), - "type": "Follow", - "id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}" - } - success = post_request(community.ap_inbox_url, follow, user.private_key, + success = True + if not community.instance.gone_forever: + follow = { + "actor": current_user.public_url(), + "to": [community.public_url()], + "object": community.public_url(), + "type": "Follow", + "id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}" + } + success = post_request(community.ap_inbox_url, follow, user.private_key, user.public_url() + '#main-key') if not success: sleep(5) # give them a rest