diff --git a/Changelog.md b/Changelog.md index 3f1edd368..8f84aec35 100644 --- a/Changelog.md +++ b/Changelog.md @@ -56,6 +56,7 @@ Ruby 2.0 is no longer officially supported. * Add a button to follow/unfollow tags to the mobile interface [#5941](https://github.com/diaspora/diaspora/pull/5941) * Add a "Manage followed tags" page to mass unfollow tags in the mobile interface [#5945](https://github.com/diaspora/diaspora/pull/5945) * Add popover/tooltip about email visibility to registration/settings page [#5956](https://github.com/diaspora/diaspora/pull/5956) +* Fetch person posts on sharing request [#5960](https://github.com/diaspora/diaspora/pull/5960) # 0.5.0.1 diff --git a/app/workers/fetch_webfinger.rb b/app/workers/fetch_webfinger.rb index dd88db32c..5dda819ef 100644 --- a/app/workers/fetch_webfinger.rb +++ b/app/workers/fetch_webfinger.rb @@ -10,7 +10,7 @@ module Workers person = Webfinger.new(account).fetch # also, schedule to fetch a few public posts from that person - Workers::FetchPublicPosts.perform_async(person.diaspora_handle) unless person.nil? + Diaspora::Fetcher::Public.queue_for(person) unless person.nil? end end end diff --git a/lib/diaspora/federated/request.rb b/lib/diaspora/federated/request.rb index a920fba7c..239c3ed4e 100644 --- a/lib/diaspora/federated/request.rb +++ b/lib/diaspora/federated/request.rb @@ -81,6 +81,9 @@ class Request user.share_with(person, user.auto_follow_back_aspect) if user.auto_follow_back && !contact.receiving + # also, schedule to fetch a few public posts from that person + Diaspora::Fetcher::Public.queue_for(person) + self end diff --git a/lib/diaspora/fetcher/public.rb b/lib/diaspora/fetcher/public.rb index 82bda6be4..cb920b243 100644 --- a/lib/diaspora/fetcher/public.rb +++ b/lib/diaspora/fetcher/public.rb @@ -13,6 +13,10 @@ module Diaspora; module Fetcher; class Public Status_Failed = 5 Status_Unfetchable = 6 + def self.queue_for(person) + Workers::FetchPublicPosts.perform_async(person.diaspora_handle) unless person.fetch_status > Status_Initial + end + # perform all actions necessary to fetch the public posts of a person # with the given diaspora_id def fetch! diaspora_id diff --git a/spec/lib/diaspora/federated/request_spec.rb b/spec/lib/diaspora/federated/request_spec.rb index c6b1fe1a1..8a15f8506 100644 --- a/spec/lib/diaspora/federated/request_spec.rb +++ b/spec/lib/diaspora/federated/request_spec.rb @@ -92,43 +92,50 @@ describe Request do :into => eve.aspects.first).receive(alice, eve.person) expect(alice.contact_for(eve.person)).to be_sharing end - + it 'shares back if auto_following is enabled' do alice.auto_follow_back = true alice.auto_follow_back_aspect = alice.aspects.first alice.save - + described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) - + expect(eve.contact_for( alice.person )).to be_sharing end - + it 'shares not back if auto_following is not enabled' do alice.auto_follow_back = false alice.auto_follow_back_aspect = alice.aspects.first alice.save - + described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) - + expect(eve.contact_for(alice.person)).to be_nil end - + it 'shares not back if already sharing' do alice.auto_follow_back = true alice.auto_follow_back_aspect = alice.aspects.first alice.save - + contact = FactoryGirl.build:contact, :user => alice, :person => eve.person, :receiving => true, :sharing => false contact.save - + expect(alice).not_to receive(:share_with) - + described_class.diaspora_initialize(:from => eve.person, :to => alice.person, :into => eve.aspects.first).receive(alice, eve.person) end + + it "queue a job to fetch public posts" do + expect(Diaspora::Fetcher::Public).to receive(:queue_for).exactly(1).times + + described_class.diaspora_initialize(from: eve.person, to: alice.person, + into: eve.aspects.first).receive(alice, eve.person) + end end context 'xml' do diff --git a/spec/lib/diaspora/fetcher/public_spec.rb b/spec/lib/diaspora/fetcher/public_spec.rb index f918d3fc5..fd0a7a824 100644 --- a/spec/lib/diaspora/fetcher/public_spec.rb +++ b/spec/lib/diaspora/fetcher/public_spec.rb @@ -25,6 +25,24 @@ describe Diaspora::Fetcher::Public do }).to_return(:body => @fixture) end + describe "#queue_for" do + it "queues a new job" do + @person.fetch_status = Diaspora::Fetcher::Public::Status_Initial + + expect(Workers::FetchPublicPosts).to receive(:perform_async).with(@person.diaspora_handle) + + Diaspora::Fetcher::Public.queue_for(@person) + end + + it "queues no job if the status is not initial" do + @person.fetch_status = Diaspora::Fetcher::Public::Status_Done + + expect(Workers::FetchPublicPosts).not_to receive(:perform_async).with(@person.diaspora_handle) + + Diaspora::Fetcher::Public.queue_for(@person) + end + end + describe "#retrieve_posts" do before do person = @person diff --git a/spec/workers/fetch_webfinger_spec.rb b/spec/workers/fetch_webfinger_spec.rb new file mode 100644 index 000000000..cfa83b24a --- /dev/null +++ b/spec/workers/fetch_webfinger_spec.rb @@ -0,0 +1,20 @@ +require "spec_helper" + +describe Workers::FetchWebfinger do + it "should webfinger and queue a job to fetch public posts" do + @person = FactoryGirl.create(:person) + allow(Webfinger).to receive(:new).and_return(double(fetch: @person)) + + expect(Diaspora::Fetcher::Public).to receive(:queue_for).exactly(1).times + + Workers::FetchWebfinger.new.perform(@person.diaspora_handle) + end + + it "should webfinger and queue no job to fetch public posts if the person is not found" do + allow(Webfinger).to receive(:new).and_return(double(fetch: nil)) + + expect(Diaspora::Fetcher::Public).not_to receive(:queue_for) + + Workers::FetchWebfinger.new.perform("unknown-person@example.net") + end +end