Change: #538 NGワード「フォローしていないアカウントへのメンションで利用できないキーワード」を、参照投稿にも適用する (#544)

* Change: #538 NGワード「フォローしていないアカウントへのメンションで利用できないキーワード」を、参照投稿にも適用する

* Update create.rb

* Update create.rb

* Update create.rb

* Fix test
This commit is contained in:
KMY(雪あすか) 2024-02-16 18:19:14 +09:00 committed by GitHub
parent 5c543c602b
commit 76b5d4f2c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 265 additions and 41 deletions

View file

@ -86,7 +86,7 @@ class UpdateStatusService < BaseService
end
def validate_status_mentions!
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if mention_to_stranger? && Setting.stranger_mention_from_local_ng && Admin::NgWord.stranger_mention_reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if (mention_to_stranger? || reference_to_stranger?) && Setting.stranger_mention_from_local_ng && Admin::NgWord.stranger_mention_reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
end
def mention_to_stranger?
@ -94,6 +94,16 @@ class UpdateStatusService < BaseService
(@status.thread.present? && @status.thread.account.id != @status.account.id && !@status.thread.account.following?(@status.account))
end
def reference_to_stranger?
referred_statuses.any? { |status| !status.account.following?(@status.account) }
end
def referred_statuses
return [] unless @options[:text]
ProcessReferencesService.extract_uris(@options[:text]).filter_map { |uri| ActivityPub::TagManager.instance.local_uri?(uri) && ActivityPub::TagManager.instance.uri_to_resource(uri, Status, url: true) }
end
def validate_media!
return [] if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable)