Fix: #162 編集/他のサーバーからの編集で、フォローしていない相手からのメンションに関するNGワードに対応 (#163)

* Fix: #162 フォローしていないアカウントへのメンションのNGワードが編集で有効にならない問題

* Fix: 他のサーバーから来た編集についても適用
This commit is contained in:
KMY(雪あすか) 2023-10-22 09:40:20 +09:00 committed by GitHub
parent 5497e2ae5d
commit 4f37ede886
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 315 additions and 9 deletions

View file

@ -35,10 +35,13 @@ class UpdateStatusService < BaseService
update_poll! if @options.key?(:poll)
update_immediate_attributes!
create_edit! unless @options[:no_history]
reset_preview_card!
process_mentions_service.call(@status)
validate_status_mentions!
end
queue_poll_notifications!
reset_preview_card!
update_metadata!
update_references!
broadcast_updates!
@ -81,6 +84,15 @@ class UpdateStatusService < BaseService
raise Mastodon::ValidationError, I18n.t('statuses.too_many_hashtags') if Admin::NgWord.hashtag_reject_with_extractor?(@options[:text])
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]}")
end
def mention_to_stranger?
@status.mentions.map(&:account).to_a.any? { |mentioned_account| mentioned_account.id != @status.account.id && !mentioned_account.following?(@status.account) } ||
(@status.thread.present? && @status.thread.account.id != @status.account.id && !@status.thread.account.following?(@status.account))
end
def validate_media!
return [] if @options[:media_ids].blank? || !@options[:media_ids].is_a?(Enumerable)
@ -167,7 +179,6 @@ class UpdateStatusService < BaseService
def update_metadata!
ProcessHashtagsService.new.call(@status)
process_mentions_service.call(@status)
@status.update(limited_scope: :circle) if process_mentions_service.mentions?
end