add author to subscribers of public shareables to ensure local delivery

This commit is contained in:
Benjamin Neff 2016-06-19 00:56:57 +02:00
parent a81bdac38c
commit 5e16b9c7cd
4 changed files with 13 additions and 6 deletions

View file

@ -46,7 +46,7 @@ module Diaspora
def subscribers def subscribers
user = author.owner user = author.owner
if public? if public?
user.contact_people [*user.contact_people, author]
else else
user.people_in_aspects(user.aspects_with_shareable(self.class, id)) user.people_in_aspects(user.aspects_with_shareable(self.class, id))
end end

View file

@ -220,23 +220,29 @@ describe Post, :type => :model do
context "public" do context "public" do
let(:post) { user.post(:status_message, text: "hello", public: true) } let(:post) { user.post(:status_message, text: "hello", public: true) }
it "returns the author to ensure local delivery" do
lonely_user = FactoryGirl.create(:user)
lonely_post = lonely_user.post(:status_message, text: "anyone?", public: true)
expect(lonely_post.subscribers).to match_array([lonely_user.person])
end
it "returns all a users contacts if the post is public" do it "returns all a users contacts if the post is public" do
second_aspect = user.aspects.create(name: "winners") second_aspect = user.aspects.create(name: "winners")
user.share_with(bob.person, second_aspect) user.share_with(bob.person, second_aspect)
expect(post.subscribers).to eq([alice.person, bob.person]) expect(post.subscribers).to match_array([alice.person, bob.person, user.person])
end end
it "adds resharers to subscribers" do it "adds resharers to subscribers" do
FactoryGirl.create(:reshare, root: post, author: eve.person) FactoryGirl.create(:reshare, root: post, author: eve.person)
expect(post.subscribers).to eq([alice.person, eve.person]) expect(post.subscribers).to match_array([alice.person, eve.person, user.person])
end end
it "adds participants to subscribers" do it "adds participants to subscribers" do
eve.participate!(post) eve.participate!(post)
expect(post.subscribers).to eq([alice.person, eve.person]) expect(post.subscribers).to match_array([alice.person, eve.person, user.person])
end end
end end
end end

View file

@ -133,7 +133,7 @@ describe Reshare, type: :model do
post = eve.post(:status_message, text: "hello", public: true) post = eve.post(:status_message, text: "hello", public: true)
reshare = FactoryGirl.create(:reshare, root: post, author: user.person) reshare = FactoryGirl.create(:reshare, root: post, author: user.person)
expect(reshare.subscribers).to eq([alice.person, eve.person]) expect(reshare.subscribers).to match_array([alice.person, eve.person, user.person])
end end
end end
end end

View file

@ -42,7 +42,8 @@ shared_examples "a dispatcher" do
context "deliver to local user" do context "deliver to local user" do
it "queues receive local job for all local receivers" do it "queues receive local job for all local receivers" do
expect(Workers::ReceiveLocal).to receive(:perform_async).with("StatusMessage", post.id, [bob.id]) local_subscriber_ids = post.subscribers.select(&:local?).map(&:owner_id)
expect(Workers::ReceiveLocal).to receive(:perform_async).with("StatusMessage", post.id, local_subscriber_ids)
Diaspora::Federation::Dispatcher.build(alice, post).dispatch Diaspora::Federation::Dispatcher.build(alice, post).dispatch
end end