From 2a99cc93ba04d0676ae667e33ee98fbc13c37345 Mon Sep 17 00:00:00 2001 From: Thorsten Claus Date: Sat, 4 Sep 2021 19:20:29 +0200 Subject: [PATCH] diaspora should send AccountMigration message back when a federation message received for a moved account I use Senya's Patch for this The extra check is for satisfying tests, which don't create real database objects. fixes #7902 closes #8288 --- Changelog.md | 1 + config/initializers/diaspora_federation.rb | 11 +++++++++++ spec/federation_callbacks_spec.rb | 10 ++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 48d7aab0a..97074f75c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,7 @@ * Add blocks to the archive export [#8263](https://github.com/diaspora/diaspora/pull/8263) * Allow points and dashes in the username [#8266](https://github.com/diaspora/diaspora/pull/8266) * Add support for footnotes in markdown [#8277](https://github.com/diaspora/diaspora/pull/8277) +* Send `AccountMigration` if receiving message to a migrated account [#8288](https://github.com/diaspora/diaspora/pull/8288) # 0.7.15.0 diff --git a/config/initializers/diaspora_federation.rb b/config/initializers/diaspora_federation.rb index 1ed4e9c98..a634f33a0 100644 --- a/config/initializers/diaspora_federation.rb +++ b/config/initializers/diaspora_federation.rb @@ -104,6 +104,17 @@ DiasporaFederation.configure do |config| on :receive_entity do |entity, sender, recipient_id| Person.by_account_identifier(sender).pod.try(:schedule_check_if_needed) + unless recipient_id.nil? + User.find_by(id: recipient_id).tap do |user| + next unless user.person.account_migration + + Diaspora::Federation::Dispatcher.build( + user, + user.person.account_migration, + subscribers: [Person.by_account_identifier(sender)] + ).dispatch + end + end case entity when DiasporaFederation::Entities::AccountDeletion diff --git a/spec/federation_callbacks_spec.rb b/spec/federation_callbacks_spec.rb index aa2848019..d9dcb4767 100644 --- a/spec/federation_callbacks_spec.rb +++ b/spec/federation_callbacks_spec.rb @@ -354,11 +354,12 @@ describe "diaspora federation callbacks" do it "receives a Retraction" do retraction = Fabricate(:retraction_entity, author: remote_person.diaspora_handle) + recipient_id = FactoryGirl.create(:user).id - expect(Diaspora::Federation::Receive).to receive(:retraction).with(retraction, 42) + expect(Diaspora::Federation::Receive).to receive(:retraction).with(retraction, recipient_id) expect(Workers::ReceiveLocal).not_to receive(:perform_async) - DiasporaFederation.callbacks.trigger(:receive_entity, retraction, retraction.author, 42) + DiasporaFederation.callbacks.trigger(:receive_entity, retraction, retraction.author, recipient_id) end it "receives a entity" do @@ -386,11 +387,12 @@ describe "diaspora federation callbacks" do it "receives a entity for a recipient" do received = Fabricate(:status_message_entity, author: remote_person.diaspora_handle) persisted = FactoryGirl.create(:status_message) + recipient_id = FactoryGirl.create(:user).id expect(Diaspora::Federation::Receive).to receive(:perform).with(received).and_return(persisted) - expect(Workers::ReceiveLocal).to receive(:perform_async).with(persisted.class.to_s, persisted.id, [42]) + expect(Workers::ReceiveLocal).to receive(:perform_async).with(persisted.class.to_s, persisted.id, [recipient_id]) - DiasporaFederation.callbacks.trigger(:receive_entity, received, received.author, 42) + DiasporaFederation.callbacks.trigger(:receive_entity, received, received.author, recipient_id) end it "does not trigger a ReceiveLocal job if Receive.perform returned nil" do