From 2711b6f523807dd1b2f1f8a7d5ce71595b5b12bb Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Sun, 29 Nov 2020 12:21:22 -0600 Subject: Only send curated Tavern posts to public timeline --- .../api/v1/statuses/bookmarks_controller.rb | 2 +- app/services/fan_out_on_write_service.rb | 30 ++++++++++++---------- app/services/favourite_service.rb | 2 +- app/services/reblog_service.rb | 2 +- app/workers/distribution_worker.rb | 5 ++-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/controllers/api/v1/statuses/bookmarks_controller.rb b/app/controllers/api/v1/statuses/bookmarks_controller.rb index d7f3d8475..32938682a 100644 --- a/app/controllers/api/v1/statuses/bookmarks_controller.rb +++ b/app/controllers/api/v1/statuses/bookmarks_controller.rb @@ -40,6 +40,6 @@ class Api::V1::Statuses::BookmarksController < Api::BaseController end def curate! - DistributionWorker.perform_async(@status.id) if @status.curate! + DistributionWorker.perform_async(@status.id, false, true) if @status.curate! end end diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 679ba8501..01b26d4ba 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -3,22 +3,24 @@ class FanOutOnWriteService < BaseService # Push a status into home and mentions feeds # @param [Status] status - def call(status, only_to_self: false) + def call(status, only_to_self: false, only_to_tavern: false) raise Mastodon::RaceConditionError if status.visibility.nil? - deliver_to_self(status) if status.account.local? - return if only_to_self || !status.published? - - if status.direct_visibility? - deliver_to_mentioned_followers(status) - deliver_to_direct_timelines(status) - deliver_to_own_conversation(status) - elsif status.limited_visibility? - deliver_to_mentioned_followers(status) - deliver_to_lists(status) - else - deliver_to_followers(status) - deliver_to_lists(status) + unless only_to_tavern + deliver_to_self(status) if status.account.local? + return if only_to_self || !status.published? + + if status.direct_visibility? + deliver_to_mentioned_followers(status) + deliver_to_direct_timelines(status) + deliver_to_own_conversation(status) + elsif status.limited_visibility? + deliver_to_mentioned_followers(status) + deliver_to_lists(status) + else + deliver_to_followers(status) + deliver_to_lists(status) + end end return if !status.public_visibility? || status.account.silenced? diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb index 0b2923165..76d5e5a5e 100644 --- a/app/services/favourite_service.rb +++ b/app/services/favourite_service.rb @@ -47,6 +47,6 @@ class FavouriteService < BaseService end def curate!(status) - DistributionWorker.perform_async(status.id) if status.curate! + DistributionWorker.perform_async(status.id, false, true) if status.curate! end end diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb index 500c743ce..3cc884ef1 100644 --- a/app/services/reblog_service.rb +++ b/app/services/reblog_service.rb @@ -65,6 +65,6 @@ class ReblogService < BaseService end def curate!(status) - DistributionWorker.perform_async(status.id) if status.curate! + DistributionWorker.perform_async(status.id, false, true) if status.curate! end end diff --git a/app/workers/distribution_worker.rb b/app/workers/distribution_worker.rb index 049d2732b..f454f7108 100644 --- a/app/workers/distribution_worker.rb +++ b/app/workers/distribution_worker.rb @@ -3,11 +3,12 @@ class DistributionWorker include Sidekiq::Worker - def perform(status_id, only_to_self = false) + def perform(status_id, only_to_self = false, only_to_tavern = false) RedisLock.acquire(redis: Redis.current, key: "distribute:#{status_id}") do |lock| if lock.acquired? status = Status.find(status_id) - FanOutOnWriteService.new.call(status, only_to_self: !status.published? || only_to_self || !status.notify?) + only_to_self ||= !(status.published? || status.notify?) + FanOutOnWriteService.new.call(status, only_to_self: only_to_self, only_to_tavern: only_to_tavern) else raise Mastodon::RaceConditionError end -- cgit