diff --git a/Changelog.md b/Changelog.md index f90fdafb8..96597a4f3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -96,6 +96,7 @@ With the port to Bootstrap 3, app/views/terms/default.haml has a new structure. * Fix notifications for interactions by non-contacts [#6498](https://github.com/diaspora/diaspora/pull/6498) * Fix issue where the publisher was broken on profile pages [#6503](https://github.com/diaspora/diaspora/pull/6503) * Prevent participations being created for invalid interactions [#6552](https://github.com/diaspora/diaspora/pull/6552) +* Improve federation for reshare related interactions [#6481](https://github.com/diaspora/diaspora/pull/6481) ## Features diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 456d12866..7946c92a7 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -59,6 +59,7 @@ class Reshare < Post def receive(recipient, sender) local_reshare = Reshare.where(:guid => self.guid).first if local_reshare && local_reshare.root.author_id == recipient.person.id + recipient.participate! self return unless recipient.has_contact_for?(sender) end super(recipient, sender) diff --git a/lib/federated/generator.rb b/lib/federated/generator.rb index da3a8390e..062d13168 100644 --- a/lib/federated/generator.rb +++ b/lib/federated/generator.rb @@ -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)) diff --git a/spec/lib/diaspora/federated/generator_spec.rb b/spec/lib/diaspora/federated/generator_spec.rb new file mode 100644 index 000000000..a7859efc6 --- /dev/null +++ b/spec/lib/diaspora/federated/generator_spec.rb @@ -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 diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index 0e13aacd4..d3cf959f4 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -51,6 +51,7 @@ describe Reshare, type: :model do receive_reshare expect(@root.resharers).to include(@reshare.author) end + it "does not error if the root author has a contact for the resharer" do bob.share_with @reshare.author, bob.aspects.first expect { @@ -59,6 +60,12 @@ describe Reshare, type: :model do end }.not_to raise_error end + + it "participates root author in the reshare" do + receive_reshare + participations = Participation.where(target_id: @reshare.id, author_id: @root.author_id) + expect(participations.count).to eq(1) + end end describe "#nsfw" do