add root author to reshare subscribers

This commit is contained in:
Benjamin Neff 2016-06-14 05:31:44 +02:00
parent 03123f1c4d
commit 57dbcc0e67
7 changed files with 19 additions and 40 deletions

View file

@ -11,7 +11,7 @@ class ResharesController < ApplicationController
end
if @reshare.save
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root_author)
current_user.dispatch_post(@reshare)
render :json => ExtremePostPresenter.new(@reshare, current_user), :status => 201
else
render :nothing => true, :status => 422

View file

@ -63,6 +63,10 @@ class Reshare < Post
@absolute_root
end
def subscribers
super + [root.author]
end
private
def root_must_be_public

View file

@ -5,27 +5,17 @@ module Federated
def initialize(user, target)
@user = user
@target = target
@dispatcher_opts ||= {}
end
def create!(options={})
relayable = build(options)
if relayable.save!
logger.info "user:#{@user.id} dispatching #{relayable.class}:#{relayable.guid}"
add_root_author(relayable)
Diaspora::Federation::Dispatcher.defer_dispatch(@user, relayable, @dispatcher_opts)
Diaspora::Federation::Dispatcher.defer_dispatch(@user, relayable)
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={})
self.class.federated_class.new(options.merge(relayable_options).merge(author_id: @user.person.id))
end

View file

@ -34,7 +34,7 @@ describe ResharesController, :type => :controller do
end
it 'calls dispatch' do
expect(bob).to receive(:dispatch_post).with(anything, hash_including(:additional_subscribers))
expect(bob).to receive(:dispatch_post)
post_request!
end

View file

@ -1,26 +0,0 @@
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(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).and_return(true)
allow(@generator).to receive(:build).and_return(@relayable)
allow(@relayable).to receive(:save!).and_return(true)
allow(@relayable).to receive(:new_record?).and_return(false)
expect(@generator).to receive(:add_root_author)
@generator.create!
end
end

View file

@ -115,4 +115,16 @@ describe Reshare, type: :model do
end
end
end
describe "#subscribers" do
it "adds root author to subscribers" do
user = FactoryGirl.create(:user_with_aspect)
user.share_with(alice.person, user.aspects.first)
post = eve.post(:status_message, text: "hello", public: true)
reshare = FactoryGirl.create(:reshare, root: post, author: user.person)
expect(reshare.subscribers).to eq([alice.person, eve.person])
end
end
end

View file

@ -27,7 +27,6 @@ class User
host: AppConfig.pod_uri.to_s
),
to: opts[:to]}
dispatch_opts.merge!(:additional_subscribers => p.root.author) if class_name == :reshare
dispatch_post(p, dispatch_opts)
end
unless opts[:created_at]