Merge pull request #6886 from SuperTux88/fix-relayable-sender

use the parent author as salmon sender, if the parent author is local
This commit is contained in:
Dennis Schubert 2016-06-26 10:36:41 +02:00
commit 5bed75b661
3 changed files with 27 additions and 0 deletions

View file

@ -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

View file

@ -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')

View file

@ -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