Add post_hash_tags_max setting
This commit is contained in:
parent
650cfae270
commit
03dabcad9c
9 changed files with 26 additions and 2 deletions
|
@ -142,7 +142,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_status?
|
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
|
end
|
||||||
|
|
||||||
def reply_to_local_account?
|
def reply_to_local_account?
|
||||||
|
|
|
@ -6,10 +6,23 @@ class Admin::NgWord
|
||||||
ng_words.any? { |word| text.include?(word) }
|
ng_words.any? { |word| text.include?(word) }
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def ng_words
|
def ng_words
|
||||||
Setting.ng_words
|
Setting.ng_words
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post_hash_tags_max
|
||||||
|
value = Setting.post_hash_tags_max
|
||||||
|
value.is_a?(Integer) && value.positive? ? value : 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,12 +37,14 @@ class Form::AdminSettings
|
||||||
ng_words
|
ng_words
|
||||||
enable_block_emoji_reaction_settings
|
enable_block_emoji_reaction_settings
|
||||||
hide_local_users_for_anonymous
|
hide_local_users_for_anonymous
|
||||||
|
post_hash_tags_max
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
INTEGER_KEYS = %i(
|
INTEGER_KEYS = %i(
|
||||||
media_cache_retention_period
|
media_cache_retention_period
|
||||||
content_cache_retention_period
|
content_cache_retention_period
|
||||||
backups_retention_period
|
backups_retention_period
|
||||||
|
post_hash_tags_max
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
BOOLEAN_KEYS = %i(
|
BOOLEAN_KEYS = %i(
|
||||||
|
|
|
@ -153,7 +153,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_status?
|
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
|
end
|
||||||
|
|
||||||
def update_immediate_attributes!
|
def update_immediate_attributes!
|
||||||
|
|
|
@ -161,6 +161,7 @@ class PostStatusService < BaseService
|
||||||
|
|
||||||
def validate_status!
|
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.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
|
end
|
||||||
|
|
||||||
def validate_media!
|
def validate_media!
|
||||||
|
|
|
@ -75,6 +75,7 @@ class UpdateStatusService < BaseService
|
||||||
|
|
||||||
def validate_status!
|
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.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
|
end
|
||||||
|
|
||||||
def validate_media!
|
def validate_media!
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
.fields-group
|
.fields-group
|
||||||
= f.input :ng_words, wrapper: :with_label, as: :text, input_html: { rows: 12 }, label: t('admin.ng_words.keywords')
|
= 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
|
.fields-group
|
||||||
= f.input :enable_block_emoji_reaction_settings, wrapper: :with_label, as: :boolean, label: t('admin.ng_words.enable_block_emoji_reaction_settings')
|
= f.input :enable_block_emoji_reaction_settings, wrapper: :with_label, as: :boolean, label: t('admin.ng_words.enable_block_emoji_reaction_settings')
|
||||||
|
|
||||||
|
|
|
@ -599,6 +599,7 @@ en:
|
||||||
enable_block_emoji_reaction_settings: Enable block emoji reactions settings for users
|
enable_block_emoji_reaction_settings: Enable block emoji reactions settings for users
|
||||||
hide_local_users_for_anonymous: Hide timeline local user posts from anonymous
|
hide_local_users_for_anonymous: Hide timeline local user posts from anonymous
|
||||||
keywords: Reject keywords
|
keywords: Reject keywords
|
||||||
|
post_hash_tags_max: Hash tags max for posts
|
||||||
title: NG words and against spams
|
title: NG words and against spams
|
||||||
relationships:
|
relationships:
|
||||||
title: "%{acct}'s relationships"
|
title: "%{acct}'s relationships"
|
||||||
|
@ -1754,6 +1755,7 @@ en:
|
||||||
show_thread: Show thread
|
show_thread: Show thread
|
||||||
sign_in_to_participate: Login to participate in the conversation
|
sign_in_to_participate: Login to participate in the conversation
|
||||||
title: '%{name}: "%{quote}"'
|
title: '%{name}: "%{quote}"'
|
||||||
|
too_many_hashtags: Too many hashtags
|
||||||
visibilities:
|
visibilities:
|
||||||
direct: Direct
|
direct: Direct
|
||||||
private: Followers-only
|
private: Followers-only
|
||||||
|
|
|
@ -598,6 +598,7 @@ ja:
|
||||||
enable_block_emoji_reaction_settings: 各ユーザーにスタンプ機能のブロック設定項目を解放する
|
enable_block_emoji_reaction_settings: 各ユーザーにスタンプ機能のブロック設定項目を解放する
|
||||||
hide_local_users_for_anonymous: ログインしていない状態でローカルユーザーの投稿をタイムラインから取得できないようにする
|
hide_local_users_for_anonymous: ログインしていない状態でローカルユーザーの投稿をタイムラインから取得できないようにする
|
||||||
keywords: 投稿できないキーワード
|
keywords: 投稿できないキーワード
|
||||||
|
post_hash_tags_max: 投稿に設定可能なハッシュタグの最大数
|
||||||
title: NGワードとスパム
|
title: NGワードとスパム
|
||||||
relationships:
|
relationships:
|
||||||
title: "%{acct} さんのフォロー・フォロワー"
|
title: "%{acct} さんのフォロー・フォロワー"
|
||||||
|
@ -1735,6 +1736,7 @@ ja:
|
||||||
show_thread: スレッドを表示
|
show_thread: スレッドを表示
|
||||||
sign_in_to_participate: ログインして会話に参加
|
sign_in_to_participate: ログインして会話に参加
|
||||||
title: '%{name}: "%{quote}"'
|
title: '%{name}: "%{quote}"'
|
||||||
|
too_many_hashtags: ハッシュタグが多すぎます
|
||||||
visibilities:
|
visibilities:
|
||||||
direct: ダイレクト
|
direct: ダイレクト
|
||||||
private: フォロワー限定
|
private: フォロワー限定
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue