Also for settings import - Don't send subscription activity to communities on dead instances

This commit is contained in:
freamon 2024-08-20 21:39:53 +00:00
parent 96cc0704e0
commit 1907c009b3

View file

@ -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 # 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) join_request = CommunityJoinRequest(user_id=user.id, community_id=community.id)
db.session.add(join_request) db.session.add(join_request)
member = CommunityMember(user_id=user.id, community_id=community.id)
db.session.add(member)
db.session.commit() db.session.commit()
follow = { success = True
"actor": current_user.public_url(), if not community.instance.gone_forever:
"to": [community.public_url()], follow = {
"object": community.public_url(), "actor": current_user.public_url(),
"type": "Follow", "to": [community.public_url()],
"id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}" "object": community.public_url(),
} "type": "Follow",
success = post_request(community.ap_inbox_url, follow, user.private_key, "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') user.public_url() + '#main-key')
if not success: if not success:
sleep(5) # give them a rest sleep(5) # give them a rest