Send comment to reshare author when commenting on reshare

As posts are always delivered also to reshare root, comments should also be delivered to reshare root, for concistency.
This commit is contained in:
Jason Robinson 2015-11-21 21:44:32 +02:00 committed by Dennis Schubert
parent 0925a26506
commit 66925918b1
2 changed files with 34 additions and 0 deletions

View file

@ -12,11 +12,20 @@ module Federated
relayable = build(options)
if relayable.save!
logger.info "user:#{@user.id} dispatching #{relayable.class}:#{relayable.guid}"
add_root_author(relayable)
Postzord::Dispatcher.defer_build_and_post(@user, relayable, @dispatcher_opts)
relayable
end
end
def add_root_author(relayable)
return unless relayable.parent.respond_to?(:root) && relayable.parent.root
# Comment post is a reshare, include original author in subscribers
root_post = relayable.parent.root
@dispatcher_opts[:additional_subscribers] ||= []
@dispatcher_opts[:additional_subscribers] << root_post.author
end
def build(options={})
options.merge!(relayable_options)
relayable = self.class.federated_class.new(options.merge(:author_id => @user.person.id))

View file

@ -0,0 +1,25 @@
require "spec_helper"
describe "adds root author on reshare" do
before do
@generator = Federated::Generator.new(double("user", id: 1), double)
@root_author = double("root_author")
root = double("root", author: @root_author)
parent = double("parent", root: root)
@relayable = double("relayable", parent: parent, class: "foo", guid: "123")
end
it "adds root to additional subscribers" do
@generator.add_root_author(@relayable)
additional_subscribers = @generator.instance_variable_get(:@dispatcher_opts)[:additional_subscribers]
expect(additional_subscribers).to include(@root_author)
end
it "calls add_root_author" do
allow(Postzord::Dispatcher).to receive(:defer_build_and_post).and_return(true)
allow(@generator).to receive(:build).and_return(@relayable)
allow(@relayable).to receive(:save!).and_return(true)
expect(@generator).to receive(:add_root_author)
@generator.create!
end
end