diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2021-10-25 04:46:48 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2021-10-25 04:46:48 +0300 |
commit | 95c0bb9ef21efd275ccdce8e81b7ab549caf9793 (patch) | |
tree | 46cb865741e042d6b4f290d6eb578086a5f10d19 /lib | |
parent | 5e47c284b602e45f1af7670f8a88dbb79822a00b (diff) | |
parent | 5714e83ab2d8e15d83757d1c0020a23fa90485c6 (diff) |
Merge branch 'next-minor' into develop
Diffstat (limited to 'lib')
-rw-r--r-- | lib/diaspora/federation.rb | 4 | ||||
-rw-r--r-- | lib/diaspora/federation/entities.rb | 5 | ||||
-rw-r--r-- | lib/diaspora/federation/receive.rb | 22 |
3 files changed, 25 insertions, 6 deletions
diff --git a/lib/diaspora/federation.rb b/lib/diaspora/federation.rb index 1a1bd96b9..8a5bd9ac4 100644 --- a/lib/diaspora/federation.rb +++ b/lib/diaspora/federation.rb @@ -9,6 +9,10 @@ module Diaspora # Raised, if the author of the existing object doesn't match the received author class InvalidAuthor < RuntimeError end + + # Raised, if the recipient account is closed already + class RecipientClosed < RuntimeError + end end end diff --git a/lib/diaspora/federation/entities.rb b/lib/diaspora/federation/entities.rb index 8a842b409..4a77f8ef7 100644 --- a/lib/diaspora/federation/entities.rb +++ b/lib/diaspora/federation/entities.rb @@ -26,8 +26,9 @@ module Diaspora def self.account_migration(account_migration) DiasporaFederation::Entities::AccountMigration.new( - author: account_migration.sender.diaspora_handle, - profile: profile(account_migration.new_person.profile) + author: account_migration.sender.diaspora_handle, + profile: profile(account_migration.new_person.profile), + signature: account_migration.signature ) end diff --git a/lib/diaspora/federation/receive.rb b/lib/diaspora/federation/receive.rb index 7ab52c2b0..5f63b72af 100644 --- a/lib/diaspora/federation/receive.rb +++ b/lib/diaspora/federation/receive.rb @@ -9,6 +9,15 @@ module Diaspora public_send(Mappings.receiver_for(entity), entity, opts) end + def self.handle_closed_recipient(sender, recipient) + return unless recipient.closed_account? + + entity = recipient.person.account_migration || recipient.person.account_deletion + Diaspora::Federation::Dispatcher.build(recipient, entity, subscribers: [sender]).dispatch if entity.present? + + raise Diaspora::Federation::RecipientClosed + end + def self.account_deletion(entity) person = author_of(entity) AccountDeletion.create!(person: person) unless AccountDeletion.where(person: person).exists? @@ -20,10 +29,15 @@ module Diaspora def self.account_migration(entity, opts) old_person = author_of(entity) profile = profile(entity.profile, opts) - return if AccountMigration.where(old_person: old_person, new_person: profile.person).exists? - AccountMigration.create!(old_person: old_person, new_person: profile.person) - rescue => e # rubocop:disable Lint/RescueWithoutErrorClass - raise e unless AccountMigration.where(old_person: old_person, new_person: profile.person).exists? + return if AccountMigration.exists?(old_person: old_person, new_person: profile.person) + + AccountMigration.create!(old_person: old_person, new_person: profile.person).tap do |migration| + migration.signature = entity.signature if old_person.local? + migration.save! + end + rescue StandardError => e + raise e unless AccountMigration.exists?(old_person: old_person, new_person: profile.person) + logger.warn "ignoring error on receive #{entity}: #{e.class}: #{e.message}" nil end |