allow to dispatch to specific subscribers
This commit is contained in:
parent
57dbcc0e67
commit
c15babdc9f
4 changed files with 52 additions and 5 deletions
|
|
@ -35,7 +35,7 @@ module Diaspora
|
|||
end
|
||||
|
||||
def deliver_to_subscribers
|
||||
local_people, remote_people = object.subscribers.partition(&:local?)
|
||||
local_people, remote_people = subscribers.partition(&:local?)
|
||||
|
||||
deliver_to_local(local_people) unless local_people.empty?
|
||||
deliver_to_remote(remote_people)
|
||||
|
|
@ -63,6 +63,14 @@ module Diaspora
|
|||
def each_service
|
||||
sender.services.where(type: opts[:service_types]).each {|service| yield(service) }
|
||||
end
|
||||
|
||||
def subscribers
|
||||
opts[:subscribers] || subscribers_from_ids || object.subscribers
|
||||
end
|
||||
|
||||
def subscribers_from_ids
|
||||
Person.where(id: opts[:subscriber_ids]) if opts[:subscriber_ids]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,9 +11,8 @@ describe Diaspora::Federation::Dispatcher::Private do
|
|||
|
||||
describe "#dispatch" do
|
||||
context "deliver to remote user" do
|
||||
let(:xml) { "<diaspora/>" }
|
||||
it "queues a private send job" do
|
||||
xml = "<diaspora/>"
|
||||
|
||||
expect(Workers::SendPrivate).to receive(:perform_async) do |user_id, _entity_string, targets|
|
||||
expect(user_id).to eq(alice.id)
|
||||
expect(targets.size).to eq(1)
|
||||
|
|
@ -36,6 +35,23 @@ describe Diaspora::Federation::Dispatcher::Private do
|
|||
|
||||
Diaspora::Federation::Dispatcher.build(bob, bobs_post).dispatch
|
||||
end
|
||||
|
||||
it "queues private send job for a specific subscriber" do
|
||||
remote_person = FactoryGirl.create(:person)
|
||||
|
||||
expect(Workers::SendPrivate).to receive(:perform_async) do |user_id, _entity_string, targets|
|
||||
expect(user_id).to eq(alice.id)
|
||||
expect(targets.size).to eq(1)
|
||||
expect(targets).to have_key(remote_person.receive_url)
|
||||
expect(targets[remote_person.receive_url]).to eq(xml)
|
||||
end
|
||||
|
||||
salmon = double
|
||||
expect(DiasporaFederation::Salmon::EncryptedSlap).to receive(:prepare).and_return(salmon)
|
||||
expect(salmon).to receive(:generate_xml).and_return(xml)
|
||||
|
||||
Diaspora::Federation::Dispatcher.build(alice, post, subscribers: [remote_person]).dispatch
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@ describe Diaspora::Federation::Dispatcher::Public do
|
|||
end
|
||||
|
||||
context "deliver to remote user" do
|
||||
let(:salmon_xml) { "<diaspora/>" }
|
||||
|
||||
it "queues a public send job" do
|
||||
alice.share_with(remote_raphael, alice.aspects.first)
|
||||
|
||||
salmon_xml = "<diaspora/>"
|
||||
|
||||
expect(Workers::SendPublic).to receive(:perform_async) do |user_id, _entity_string, urls, xml|
|
||||
expect(user_id).to eq(alice.id)
|
||||
expect(urls.size).to eq(1)
|
||||
|
|
@ -72,6 +72,19 @@ describe Diaspora::Federation::Dispatcher::Public do
|
|||
|
||||
Diaspora::Federation::Dispatcher.build(alice, post).dispatch
|
||||
end
|
||||
|
||||
it "queues public send job for a specific subscriber" do
|
||||
expect(Workers::SendPublic).to receive(:perform_async) do |user_id, _entity_string, urls, xml|
|
||||
expect(user_id).to eq(alice.id)
|
||||
expect(urls.size).to eq(1)
|
||||
expect(urls[0]).to eq(remote_raphael.pod.url_to("/receive/public"))
|
||||
expect(xml).to eq(salmon_xml)
|
||||
end
|
||||
|
||||
expect(DiasporaFederation::Salmon::Slap).to receive(:generate_xml).and_return(salmon_xml)
|
||||
|
||||
Diaspora::Federation::Dispatcher.build(alice, post, subscribers: [remote_raphael]).dispatch
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,16 @@ shared_examples "a dispatcher" do
|
|||
|
||||
Diaspora::Federation::Dispatcher.build(alice, object).dispatch
|
||||
end
|
||||
|
||||
it "queues receive local job for a specific subscriber" do
|
||||
expect(Workers::ReceiveLocal).to receive(:perform_async).with("StatusMessage", post.id, [eve.id])
|
||||
Diaspora::Federation::Dispatcher.build(alice, post, subscribers: [eve.person]).dispatch
|
||||
end
|
||||
|
||||
it "queues receive local job for a specific subscriber id" do
|
||||
expect(Workers::ReceiveLocal).to receive(:perform_async).with("StatusMessage", post.id, [eve.id])
|
||||
Diaspora::Federation::Dispatcher.build(alice, post, subscriber_ids: [eve.person.id]).dispatch
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue