parent
5424567aef
commit
7411941885
11 changed files with 94 additions and 5 deletions
|
@ -143,8 +143,9 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||
end
|
||||
|
||||
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.reject?("#{@params[:spoiler_text]}\n#{@params[:text]}", uri: @params[:uri], target_type: :status, public: @status_parser.distributable_visibility?)
|
||||
valid = !Admin::NgWord.hashtag_reject?(@tags.size) if valid
|
||||
valid = !Admin::NgWord.mention_reject?(@mentions.count { |m| !m.silent }) if valid
|
||||
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
|
||||
|
|
|
@ -26,6 +26,14 @@ class Admin::NgWord
|
|||
hashtag_reject?(Extractor.extract_hashtags(text)&.size || 0)
|
||||
end
|
||||
|
||||
def mention_reject?(mention_count)
|
||||
post_mentions_max.positive? && post_mentions_max < mention_count
|
||||
end
|
||||
|
||||
def mention_reject_with_extractor?(text)
|
||||
mention_reject?(text.gsub(Account::MENTION_RE)&.count || 0)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def include?(text, word)
|
||||
|
@ -49,6 +57,11 @@ class Admin::NgWord
|
|||
value.is_a?(Integer) && value.positive? ? value : 0
|
||||
end
|
||||
|
||||
def post_mentions_max
|
||||
value = Setting.post_mentions_max
|
||||
value.is_a?(Integer) && value.positive? ? value : 0
|
||||
end
|
||||
|
||||
def record!(type, text, keyword, options)
|
||||
return unless options[:uri] && options[:target_type]
|
||||
return if options.key?(:public) && !options.delete(:public)
|
||||
|
|
|
@ -49,6 +49,7 @@ class Form::AdminSettings
|
|||
stranger_mention_from_local_ng
|
||||
hide_local_users_for_anonymous
|
||||
post_hash_tags_max
|
||||
post_mentions_max
|
||||
sensitive_words
|
||||
sensitive_words_for_full
|
||||
authorized_fetch
|
||||
|
@ -69,6 +70,7 @@ class Form::AdminSettings
|
|||
content_cache_retention_period
|
||||
backups_retention_period
|
||||
post_hash_tags_max
|
||||
post_mentions_max
|
||||
registrations_limit
|
||||
registrations_limit_per_day
|
||||
registrations_start_hour
|
||||
|
|
|
@ -161,7 +161,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
|||
end
|
||||
|
||||
def valid_status?
|
||||
!Admin::NgWord.reject?("#{@status_parser.spoiler_text}\n#{@status_parser.text}", uri: @status.uri, target_type: :status) && !Admin::NgWord.hashtag_reject?(@raw_tags.size)
|
||||
!Admin::NgWord.reject?("#{@status_parser.spoiler_text}\n#{@status_parser.text}", uri: @status.uri, target_type: :status) && !Admin::NgWord.hashtag_reject?(@raw_tags.size) && !Admin::NgWord.mention_reject?(@raw_mentions.size)
|
||||
end
|
||||
|
||||
def validate_status_mentions!
|
||||
|
|
|
@ -209,7 +209,8 @@ class PostStatusService < BaseService
|
|||
|
||||
def validate_status!
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if Admin::NgWord.reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.too_many_hashtags') if Admin::NgWord.hashtag_reject_with_extractor?(@options[:text])
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.too_many_hashtags') if Admin::NgWord.hashtag_reject_with_extractor?(@text)
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.too_many_mentions') if Admin::NgWord.mention_reject_with_extractor?(@text)
|
||||
end
|
||||
|
||||
def validate_status_mentions!
|
||||
|
|
|
@ -82,7 +82,8 @@ class UpdateStatusService < BaseService
|
|||
|
||||
def validate_status!
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if Admin::NgWord.reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.too_many_hashtags') if Admin::NgWord.hashtag_reject_with_extractor?(@options[:text])
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.too_many_hashtags') if Admin::NgWord.hashtag_reject_with_extractor?(@options[:text] || '')
|
||||
raise Mastodon::ValidationError, I18n.t('statuses.too_many_mentions') if Admin::NgWord.mention_reject_with_extractor?(@options[:text] || '')
|
||||
end
|
||||
|
||||
def validate_status_mentions!
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
.fields-group
|
||||
= f.input :post_hash_tags_max, wrapper: :with_label, as: :integer, label: t('admin.ng_words.post_hash_tags_max')
|
||||
|
||||
.fields-group
|
||||
= f.input :post_mentions_max, wrapper: :with_label, as: :integer, label: t('admin.ng_words.post_mentions_max')
|
||||
|
||||
.fields-group
|
||||
= f.input :hide_local_users_for_anonymous, wrapper: :with_label, as: :boolean, label: t('admin.ng_words.hide_local_users_for_anonymous')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue