1
0
Fork 0
forked from gitea/nas

Add post_hash_tags_max setting

This commit is contained in:
KMY 2023-07-24 12:45:34 +09:00
parent 650cfae270
commit 03dabcad9c
9 changed files with 26 additions and 2 deletions

View file

@ -142,7 +142,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
end
def valid_status?
!Admin::NgWord.reject?("#{@params[:spoiler_text]}\n#{@params[:text]}")
!Admin::NgWord.reject?("#{@params[:spoiler_text]}\n#{@params[:text]}") && !Admin::NgWord.hashtag_reject?(@tags.size)
end
def reply_to_local_account?

View file

@ -6,10 +6,23 @@ class Admin::NgWord
ng_words.any? { |word| text.include?(word) }
end
def hashtag_reject?(hashtag_count)
post_hash_tags_max.positive? && post_hash_tags_max < hashtag_count
end
def hashtag_reject_with_extractor?(text)
hashtag_reject?(Extractor.extract_hashtags(text)&.size || 0)
end
private
def ng_words
Setting.ng_words
end
def post_hash_tags_max
value = Setting.post_hash_tags_max
value.is_a?(Integer) && value.positive? ? value : 0
end
end
end

View file

@ -37,12 +37,14 @@ class Form::AdminSettings
ng_words
enable_block_emoji_reaction_settings
hide_local_users_for_anonymous
post_hash_tags_max
).freeze
INTEGER_KEYS = %i(
media_cache_retention_period
content_cache_retention_period
backups_retention_period
post_hash_tags_max
).freeze
BOOLEAN_KEYS = %i(

View file

@ -153,7 +153,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
end
def valid_status?
!Admin::NgWord.reject?("#{@status_parser.spoiler_text}\n#{@status_parser.text}")
!Admin::NgWord.reject?("#{@status_parser.spoiler_text}\n#{@status_parser.text}") && !Admin::NgWord.hashtag_reject?(@tags.size)
end
def update_immediate_attributes!

View file

@ -161,6 +161,7 @@ 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])
end
def validate_media!

View file

@ -75,6 +75,7 @@ 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])
end
def validate_media!

View file

@ -10,6 +10,9 @@
.fields-group
= f.input :ng_words, wrapper: :with_label, as: :text, input_html: { rows: 12 }, label: t('admin.ng_words.keywords')
.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 :enable_block_emoji_reaction_settings, wrapper: :with_label, as: :boolean, label: t('admin.ng_words.enable_block_emoji_reaction_settings')