mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Don't send subscription activity to communities on dead instances
This commit is contained in:
parent
3ff54c54da
commit
96cc0704e0
3 changed files with 34 additions and 36 deletions
|
@ -55,6 +55,9 @@ def unsubscribe_from_everything_then_delete_task(user_id):
|
|||
|
||||
|
||||
def unsubscribe_from_community(community, user):
|
||||
if community.instance.gone_forever:
|
||||
return
|
||||
|
||||
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
||||
follow = {
|
||||
"actor": user.public_url(),
|
||||
|
@ -70,13 +73,7 @@ def unsubscribe_from_community(community, user):
|
|||
'id': undo_id,
|
||||
'object': follow
|
||||
}
|
||||
activity = ActivityPubLog(direction='out', activity_id=undo_id, activity_type='Undo',
|
||||
activity_json=json.dumps(undo), result='processing')
|
||||
db.session.add(activity)
|
||||
db.session.commit()
|
||||
post_request(community.ap_inbox_url, undo, user.private_key, user.public_url() + '#main-key')
|
||||
activity.result = 'success'
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def send_newsletter(form):
|
||||
|
|
|
@ -403,6 +403,8 @@ def subscribe(actor):
|
|||
join_request = CommunityJoinRequest(user_id=current_user.id, community_id=community.id)
|
||||
db.session.add(join_request)
|
||||
db.session.commit()
|
||||
success = True
|
||||
if not community.instance.gone_forever:
|
||||
follow = {
|
||||
"actor": current_user.public_url(),
|
||||
"to": [community.public_url()],
|
||||
|
@ -442,6 +444,8 @@ def unsubscribe(actor):
|
|||
proceed = True
|
||||
# Undo the Follow
|
||||
if '@' in actor: # this is a remote community, so activitypub is needed
|
||||
success = True
|
||||
if not community.instance.gone_forever:
|
||||
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
||||
follow = {
|
||||
"actor": current_user.public_url(),
|
||||
|
|
|
@ -91,6 +91,9 @@ def purge_user_then_delete_task(user_id):
|
|||
|
||||
|
||||
def unsubscribe_from_community(community, user):
|
||||
if community.instance.gone_forever:
|
||||
return
|
||||
|
||||
undo_id = f"https://{current_app.config['SERVER_NAME']}/activities/undo/" + gibberish(15)
|
||||
follow = {
|
||||
"actor": user.public_url(),
|
||||
|
@ -106,13 +109,7 @@ def unsubscribe_from_community(community, user):
|
|||
'id': undo_id,
|
||||
'object': follow
|
||||
}
|
||||
activity = ActivityPubLog(direction='out', activity_id=undo_id, activity_type='Undo',
|
||||
activity_json=json.dumps(undo), result='processing')
|
||||
db.session.add(activity)
|
||||
db.session.commit()
|
||||
post_request(community.ap_inbox_url, undo, user.private_key, user.public_url() + '#main-key')
|
||||
activity.result = 'success'
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def search_for_user(address: str):
|
||||
|
|
Loading…
Add table
Reference in a new issue