diff --git a/lib/diaspora/federation/dispatcher.rb b/lib/diaspora/federation/dispatcher.rb index 66bdc9932..c2b212a56 100644 --- a/lib/diaspora/federation/dispatcher.rb +++ b/lib/diaspora/federation/dispatcher.rb @@ -10,6 +10,7 @@ module Diaspora end def self.build(sender, object, opts={}) + sender = object.try(:sender_for_dispatch) || sender if object.try(:public?) Public.new(sender, object, opts) else diff --git a/lib/diaspora/relayable.rb b/lib/diaspora/relayable.rb index e3a481d05..8db901f4a 100644 --- a/lib/diaspora/relayable.rb +++ b/lib/diaspora/relayable.rb @@ -40,6 +40,11 @@ module Diaspora end end + # @deprecated This is only needed for pre 0.6 pods + def sender_for_dispatch + parent.author.owner if parent.author.local? + end + # @abstract def parent raise NotImplementedError.new('you must override parent in order to enable relayable on this model') diff --git a/spec/lib/diaspora/federation/dispatcher_spec.rb b/spec/lib/diaspora/federation/dispatcher_spec.rb index fa27eea7c..40ab01dc8 100644 --- a/spec/lib/diaspora/federation/dispatcher_spec.rb +++ b/spec/lib/diaspora/federation/dispatcher_spec.rb @@ -32,6 +32,27 @@ describe Diaspora::Federation::Dispatcher do expect(dispatcher).to be_instance_of(Diaspora::Federation::Dispatcher::Private) end + + it "uses the parent author as sender for a comment if the parent is local" do + comment = FactoryGirl.create(:comment, author: bob.person, post: post) + + expect(Diaspora::Federation::Dispatcher::Public).to receive(:new).with(alice, comment, {}).and_call_original + + dispatcher = described_class.build(bob, comment) + + expect(dispatcher).to be_instance_of(Diaspora::Federation::Dispatcher::Public) + end + + it "uses the original sender for a comment if the parent is not local" do + remote_post = FactoryGirl.create(:status_message, author: remote_raphael, text: "hello", public: true) + comment = FactoryGirl.create(:comment, author: bob.person, post: remote_post) + + expect(Diaspora::Federation::Dispatcher::Public).to receive(:new).with(bob, comment, {}).and_call_original + + dispatcher = described_class.build(bob, comment) + + expect(dispatcher).to be_instance_of(Diaspora::Federation::Dispatcher::Public) + end end describe ".defer_dispatch" do