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

@ -83,8 +83,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
process_audience
return nil unless valid_status?
return nil if (reply_to_local? || reply_to_local_account? || reply_to_local_from_tags?) && reject_reply_to_local?
return nil if mention_to_local_but_not_followed? && reject_reply_exclude_followers?
return nil if (mention_to_local? || reference_to_local_account?) && reject_reply_to_local?
return nil if (mention_to_local_stranger? || reference_to_local_stranger?) && reject_reply_exclude_followers?
ApplicationRecord.transaction do
@status = Status.create!(@params)
@ -145,7 +145,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def valid_status?
valid = !Admin::NgWord.reject?("#{@params[:spoiler_text]}\n#{@params[:text]}", uri: @params[:uri], target_type: :status, public: @status_parser.distributable_visibility?) && !Admin::NgWord.hashtag_reject?(@tags.size)
valid = !Admin::NgWord.stranger_mention_reject?("#{@params[:spoiler_text]}\n#{@params[:text]}", uri: @params[:uri], target_type: :status, public: @status_parser.distributable_visibility?) if valid && mention_to_local_but_not_followed?
valid = !Admin::NgWord.stranger_mention_reject?("#{@params[:spoiler_text]}\n#{@params[:text]}", uri: @params[:uri], target_type: :status, public: @status_parser.distributable_visibility?) if valid && (mention_to_local_stranger? || reference_to_local_stranger?)
valid
end
@ -447,32 +447,30 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
@skip_download ||= DomainBlock.reject_media?(@account.domain)
end
def reply_to_local_account?
accounts_in_audience.any?(&:local?)
end
def reply_to_local_account_following?
!reply_to_local_account? || accounts_in_audience.none? { |account| account.local? && !account.following?(@account) }
end
def reply_to_local_from_tags?
@mentions.present? && @mentions.any? { |m| m.account.local? }
end
def reply_to_local_from_tags_following?
@mentions.nil? || @mentions.none? { |m| m.account.local? && !m.account.following?(@account) }
end
def reply_to_local?
!replied_to_status.nil? && replied_to_status.account.local?
end
def reply_to_local_status_following?
!reply_to_local? || replied_to_status.account.following?(@account)
def mention_to_local?
mentioned_accounts.any?(&:local?)
end
def mention_to_local_but_not_followed?
!reply_to_local_account_following? || !reply_to_local_status_following? || !reply_to_local_from_tags_following?
def mention_to_local_stranger?
mentioned_accounts.any? { |account| account.local? && !account.following?(@account) }
end
def mentioned_accounts
return @mentioned_accounts if defined?(@mentioned_accounts)
@mentioned_accounts = (accounts_in_audience + [replied_to_status&.account] + (@mentions&.map(&:account) || [])).compact.uniq
end
def reference_to_local_account?
local_referred_accounts.any?
end
def reference_to_local_stranger?
local_referred_accounts.any? { |account| !account.following?(@account) }
end
def reject_reply_to_local?
@ -540,10 +538,25 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
retry
end
def process_references!
references = @object['references'].nil? ? [] : ActivityPub::FetchReferencesService.new.call(@status, @object['references'])
def reference_uris
return @reference_uris if defined?(@reference_uris)
ProcessReferencesService.call_service_without_error(@status, [], references, [quote].compact)
@reference_uris = @object['references'].nil? ? [] : (ActivityPub::FetchReferencesService.new.call(@account, @object['references']) || []).uniq
@reference_uris += ProcessReferencesService.extract_uris(@object['content'] || '')
end
def local_referred_accounts
return @local_referred_accounts if defined?(@local_referred_accounts)
local_referred_statuses = reference_uris.filter_map do |uri|
ActivityPub::TagManager.instance.local_uri?(uri) && ActivityPub::TagManager.instance.uri_to_resource(uri, Status)
end.compact
@local_referred_accounts = local_referred_statuses.map(&:account)
end
def process_references!
ProcessReferencesService.call_service_without_error(@status, [], reference_uris, [quote].compact)
end
def quote_local?