Add: #40 拡張ドメインブロックに「トレンドに掲載しない」を追加 (#492)

This commit is contained in:
KMY(雪あすか) 2024-01-22 09:06:05 +09:00 committed by GitHub
parent 96da1fcb00
commit 8793bc286e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 71 additions and 10 deletions

View file

@ -24,6 +24,7 @@
# detect_invalid_subscription :boolean default(FALSE), not null
# reject_reply_exclude_followers :boolean default(FALSE), not null
# reject_friend :boolean default(FALSE), not null
# block_trends :boolean default(FALSE), not null
#
class DomainBlock < ApplicationRecord
@ -49,6 +50,7 @@ class DomainBlock < ApplicationRecord
.or(where(reject_new_follow: true))
.or(where(reject_straight_follow: true))
.or(where(reject_friend: true))
.or(where(block_trends: true))
}
scope :by_severity, -> { in_order_of(:severity, %w(noop silence suspend)).order(:domain) }
@ -70,6 +72,7 @@ class DomainBlock < ApplicationRecord
reject_straight_follow? ? :reject_straight_follow : nil,
reject_new_follow? ? :reject_new_follow : nil,
reject_friend? ? :reject_friend : nil,
block_trends? ? :block_trends : nil,
detect_invalid_subscription? ? :detect_invalid_subscription : nil,
reject_reports? ? :reject_reports : nil].reject { |policy| policy == :noop || policy.nil? }
end
@ -116,6 +119,10 @@ class DomainBlock < ApplicationRecord
!!rule_for(domain)&.reject_friend?
end
def block_trends?(domain)
!!rule_for(domain)&.block_trends?
end
def detect_invalid_subscription?(domain)
!!rule_for(domain)&.detect_invalid_subscription?
end

View file

@ -110,7 +110,13 @@ class Trends::Statuses < Trends::Base
(status.public_visibility? || status.public_unlisted_visibility?) &&
status.account.discoverable? && !status.account.silenced? && !status.account.sensitized? &&
status.spoiler_text.blank? && (!status.sensitive? || status.media_attachments.none?) &&
!status.reply? && valid_locale?(status.language)
!status.reply? && valid_locale?(status.language) && !domain_blocked?(status)
end
def domain_blocked?(status)
return false if status.account.local?
DomainBlock.block_trends?(status.account.domain)
end
def calculate_scores(statuses, at_time)