From caad1e2628c78d2dfcd86e3a79b0849dc89baf16 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 16 Apr 2024 09:16:54 -0400 Subject: [PATCH] Add scope `Status.distributable_visibility` (#29950) --- app/controllers/accounts_controller.rb | 2 +- app/controllers/activitypub/replies_controller.rb | 2 +- .../api/v1/statuses/reblogged_by_accounts_controller.rb | 2 +- app/lib/account_statuses_filter.rb | 2 +- app/models/admin/status_filter.rb | 2 +- app/models/announcement.rb | 2 +- app/models/concerns/status/threading_concern.rb | 2 +- app/models/featured_tag.rb | 2 +- app/models/status.rb | 1 + 9 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 4e475fe782..32549e1516 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -46,7 +46,7 @@ class AccountsController < ApplicationController end def default_statuses - @account.statuses.where(visibility: [:public, :unlisted]) + @account.statuses.distributable_visibility end def only_media_scope diff --git a/app/controllers/activitypub/replies_controller.rb b/app/controllers/activitypub/replies_controller.rb index 3f43e89a5e..11aac48c9c 100644 --- a/app/controllers/activitypub/replies_controller.rb +++ b/app/controllers/activitypub/replies_controller.rb @@ -31,7 +31,7 @@ class ActivityPub::RepliesController < ActivityPub::BaseController def set_replies @replies = only_other_accounts? ? Status.where.not(account_id: @account.id).joins(:account).merge(Account.without_suspended) : @account.statuses - @replies = @replies.where(in_reply_to_id: @status.id, visibility: [:public, :unlisted]) + @replies = @replies.distributable_visibility.where(in_reply_to_id: @status.id) @replies = @replies.paginate_by_min_id(DESCENDANTS_LIMIT, params[:min_id]) end diff --git a/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb b/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb index eaa5ef7255..bac96b032b 100644 --- a/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb +++ b/app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb @@ -23,7 +23,7 @@ class Api::V1::Statuses::RebloggedByAccountsController < Api::V1::Statuses::Base end def paginated_statuses - Status.where(reblog_of_id: @status.id).where(visibility: [:public, :unlisted]).paginate_by_max_id( + Status.where(reblog_of_id: @status.id).distributable_visibility.paginate_by_max_id( limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id] diff --git a/app/lib/account_statuses_filter.rb b/app/lib/account_statuses_filter.rb index eb7592cdce..cfc9be9660 100644 --- a/app/lib/account_statuses_filter.rb +++ b/app/lib/account_statuses_filter.rb @@ -35,7 +35,7 @@ class AccountStatusesFilter return Status.none if account.unavailable? if anonymous? - account.statuses.where(visibility: %i(public unlisted)) + account.statuses.distributable_visibility elsif author? account.statuses.all # NOTE: #merge! does not work without the #all elsif blocked? diff --git a/app/models/admin/status_filter.rb b/app/models/admin/status_filter.rb index 4708785e7d..8d20e4f6ab 100644 --- a/app/models/admin/status_filter.rb +++ b/app/models/admin/status_filter.rb @@ -16,7 +16,7 @@ class Admin::StatusFilter end def results - scope = @account.statuses.where(visibility: [:public, :unlisted]) + scope = @account.statuses.distributable_visibility params.each do |key, value| next if IGNORED_PARAMS.include?(key.to_s) diff --git a/app/models/announcement.rb b/app/models/announcement.rb index e630570020..5ce382dc18 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -62,7 +62,7 @@ class Announcement < ApplicationRecord @statuses ||= if status_ids.nil? [] else - Status.where(id: status_ids, visibility: [:public, :unlisted]) + Status.where(id: status_ids).distributable_visibility end end diff --git a/app/models/concerns/status/threading_concern.rb b/app/models/concerns/status/threading_concern.rb index 2606fd2f27..ca8c448140 100644 --- a/app/models/concerns/status/threading_concern.rb +++ b/app/models/concerns/status/threading_concern.rb @@ -12,7 +12,7 @@ module Status::ThreadingConcern end def self_replies(limit) - account.statuses.where(in_reply_to_id: id, visibility: [:public, :unlisted]).reorder(id: :asc).limit(limit) + account.statuses.distributable_visibility.where(in_reply_to_id: id).reorder(id: :asc).limit(limit) end private diff --git a/app/models/featured_tag.rb b/app/models/featured_tag.rb index ea8aa4787c..cdd97205eb 100644 --- a/app/models/featured_tag.rb +++ b/app/models/featured_tag.rb @@ -74,6 +74,6 @@ class FeaturedTag < ApplicationRecord end def visible_tagged_account_statuses - account.statuses.where(visibility: %i(public unlisted)).tagged_with(tag) + account.statuses.distributable_visibility.tagged_with(tag) end end diff --git a/app/models/status.rb b/app/models/status.rb index 8ab78d09d6..c2d7985b4d 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -121,6 +121,7 @@ class Status < ApplicationRecord scope :tagged_with_none, lambda { |tag_ids| where('NOT EXISTS (SELECT * FROM statuses_tags forbidden WHERE forbidden.status_id = statuses.id AND forbidden.tag_id IN (?))', tag_ids) } + scope :distributable_visibility, -> { where(visibility: %i(public unlisted)) } scope :list_eligible_visibility, -> { where(visibility: %i(public unlisted private)) } after_create_commit :trigger_create_webhooks