Add: 検索許可「ローカルとフォロワー」 (#60)

This commit is contained in:
KMY(雪あすか) 2023-10-05 16:37:27 +09:00 committed by GitHub
parent deb8642e95
commit 235bef36d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 210 additions and 25 deletions

View file

@ -5,7 +5,7 @@ module StatusSearchConcern
included do
scope :indexable, -> { without_reblogs.where(visibility: [:public, :login], searchability: nil).joins(:account).where(account: { indexable: true }) }
scope :remote_dynamic_searchability, -> { remote.where(searchability: [:public, :private]) }
scope :remote_dynamic_searchability, -> { remote.where(searchability: [:public, :public_unlisted, :private]) }
end
def searchable_by

View file

@ -129,7 +129,7 @@ class Status < ApplicationRecord
scope :without_replies, -> { where('statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id') }
scope :without_reblogs, -> { where(statuses: { reblog_of_id: nil }) }
scope :with_public_visibility, -> { where(visibility: [:public, :public_unlisted, :login]) }
scope :with_public_search_visibility, -> { merge(where(visibility: [:public, :public_unlisted, :login]).or(Status.where(searchability: :public))) }
scope :with_public_search_visibility, -> { merge(where(visibility: [:public, :public_unlisted, :login]).or(Status.where(searchability: [:public, :public_unlisted]))) }
scope :with_global_timeline_visibility, -> { where(visibility: [:public, :login]) }
scope :tagged_with, ->(tag_ids) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag_ids }) }
scope :excluding_silenced_accounts, -> { left_outer_joins(:account).where(accounts: { silenced_at: nil }) }
@ -442,19 +442,26 @@ class Status < ApplicationRecord
def compute_searchability
local = account.local?
check_searchability = public_unlisted_searchability? ? 'public' : searchability
return 'private' if public_searchability? && account.silenced?
return 'private' if %w(public public_unlisted).include?(check_searchability) && account.silenced?
return 'direct' if unsupported_searchability?
return searchability if local && !searchability.nil?
return 'direct' if local || [:public, :private, :direct, :limited].exclude?(account.searchability.to_sym)
return check_searchability if local && !check_searchability.nil?
return 'direct' if local || %i(public private direct limited).exclude?(account.searchability.to_sym)
account_searchability = Status.searchabilities[account.searchability]
status_searchability = Status.searchabilities[searchability.nil? ? 'direct' : searchability]
status_searchability = Status.searchabilities[check_searchability.nil? ? 'direct' : check_searchability]
Status.searchabilities.invert.fetch([account_searchability, status_searchability].max) || 'direct'
end
def compute_searchability_activitypub
return 'private' if public_unlisted_visibility? && public_searchability?
return 'private' if public_unlisted_searchability?
compute_searchability
end
def compute_searchability_local
return 'public_unlisted' if public_unlisted_searchability?
compute_searchability
end
@ -477,6 +484,10 @@ class Status < ApplicationRecord
end
def selectable_searchabilities
searchabilities.keys - %w(unsupported)
end
def selectable_searchabilities_for_search
searchabilities.keys - %w(public_unlisted unsupported)
end
@ -620,7 +631,7 @@ class Status < ApplicationRecord
elsif visibility == 'limited'
:limited
elsif visibility == 'private'
searchability == 'public' ? :private : searchability
searchability == 'public' || searchability == 'public_unlisted' ? :private : searchability
elsif visibility == 'direct'
searchability == 'limited' ? :limited : :direct
else

View file

@ -106,7 +106,8 @@ class Trends::Statuses < Trends::Base
private
def eligible?(status)
(status.searchability.nil? || status.public_searchability?) && (status.public_visibility? || status.public_unlisted_visibility?) &&
(status.searchability.nil? || status.compute_searchability == 'public') &&
(status.public_visibility? || status.public_unlisted_visibility?) &&
status.account.discoverable? && !status.account.silenced? && status.spoiler_text.blank? && (!status.sensitive? || status.media_attachments.none?) &&
!status.reply? && valid_locale?(status.language)
end