From bd110a3d7d491b2704c98a60b9a9ef483a72d846 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 18 Apr 2017 21:44:52 +0200 Subject: [PATCH] Make private toots get PuSHed to subscription URLs that belong to domains where you have approved followers --- app/models/account.rb | 4 ++++ app/workers/pubsubhubbub/distribution_worker.rb | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/account.rb b/app/models/account.rb index 259a874511..01abe26254 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -128,6 +128,10 @@ class Account < ApplicationRecord !subscription_expires_at.blank? end + def followers_domains + followers.reorder(nil).pluck('distinct accounts.domain') + end + def favourited?(status) status.proper.favourites.where(account: self).count.positive? end diff --git a/app/workers/pubsubhubbub/distribution_worker.rb b/app/workers/pubsubhubbub/distribution_worker.rb index 68ca0f870c..04682c42e5 100644 --- a/app/workers/pubsubhubbub/distribution_worker.rb +++ b/app/workers/pubsubhubbub/distribution_worker.rb @@ -8,12 +8,14 @@ class Pubsubhubbub::DistributionWorker def perform(stream_entry_id) stream_entry = StreamEntry.find(stream_entry_id) - return if stream_entry.hidden? + return if stream_entry.status.direct_visibility? account = stream_entry.account payload = AtomSerializer.render(AtomSerializer.new.feed(account, [stream_entry])) + domains = account.followers_domains Subscription.where(account: account).active.select('id, callback_url').find_each do |subscription| + next unless domains.include?(Addressable::URI.parse(subscription.callback_url).host) Pubsubhubbub::DeliveryWorker.perform_async(subscription.id, payload) end rescue ActiveRecord::RecordNotFound