diff --git a/app/models/account.rb b/app/models/account.rb index 670b2c6083..fe7a87d7eb 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -336,6 +336,7 @@ class Account < ApplicationRecord end def emoji_reactions_must_following? + return false unless Setting.enable_block_emoji_reaction_settings return user&.settings&.[]('emoji_reactions.must_be_following') || false if user.present? return settings['emoji_reactions_must_be_following'] || false if settings.present? @@ -343,6 +344,7 @@ class Account < ApplicationRecord end def emoji_reactions_must_follower? + return false unless Setting.enable_block_emoji_reaction_settings return user&.settings&.[]('emoji_reactions.must_be_follower') || false if user.present? return settings['emoji_reaction_must_be_follower'] || false if settings.present? @@ -350,6 +352,7 @@ class Account < ApplicationRecord end def emoji_reactions_deny_from_all? + return false unless Setting.enable_block_emoji_reaction_settings return user&.settings&.[]('emoji_reactions.deny_from_all') || false if user.present? return settings['emoji_reaction_deny_from_all'] || false if settings.present? diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 89625249d3..61071a5b76 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -35,6 +35,7 @@ class Form::AdminSettings status_page_url captcha_enabled ng_words + enable_block_emoji_reaction_settings ).freeze INTEGER_KEYS = %i( @@ -55,6 +56,7 @@ class Form::AdminSettings noindex require_invite_text captcha_enabled + enable_block_emoji_reaction_settings ).freeze UPLOAD_KEYS = %i( diff --git a/app/validators/emoji_reaction_validator.rb b/app/validators/emoji_reaction_validator.rb index 4d45a77468..e7da9d0724 100644 --- a/app/validators/emoji_reaction_validator.rb +++ b/app/validators/emoji_reaction_validator.rb @@ -8,7 +8,7 @@ class EmojiReactionValidator < ActiveModel::Validator emoji_reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if emoji_reaction.custom_emoji_id.blank? && !unicode_emoji?(emoji_reaction.name) emoji_reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if emoji_reaction.custom_emoji_id.present? && disabled_custom_emoji?(emoji_reaction.custom_emoji) - emoji_reaction.errors.add(:name, I18n.t('reactions.errors.banned')) if deny_from_all?(emoji_reaction) || non_follower?(emoji_reaction) || non_following?(emoji_reaction) + emoji_reaction.errors.add(:name, I18n.t('reactions.errors.banned')) if deny_emoji_reactions?(emoji_reaction) end private @@ -21,24 +21,23 @@ class EmojiReactionValidator < ActiveModel::Validator custom_emoji.nil? ? false : custom_emoji.disabled end - def deny_from_all?(emoji_reaction) + def deny_emoji_reactions?(emoji_reaction) + return false unless Setting.enable_block_emoji_reaction_settings return false if emoji_reaction.status.account.user.nil? return false if emoji_reaction.status.account_id == emoji_reaction.account_id + deny_from_all?(emoji_reaction) || non_follower?(emoji_reaction) || non_following?(emoji_reaction) + end + + def deny_from_all?(emoji_reaction) emoji_reaction.status.account.user.settings['emoji_reactions.deny_from_all'] end def non_following?(emoji_reaction) - return false if emoji_reaction.status.account.user.nil? - return false if emoji_reaction.status.account_id == emoji_reaction.account_id - emoji_reaction.status.account.user.settings['emoji_reactions.must_be_following'] && !emoji_reaction.status.account.following?(emoji_reaction.account) end def non_follower?(emoji_reaction) - return false if emoji_reaction.status.account.user.nil? - return false if emoji_reaction.status.account_id == emoji_reaction.account_id - emoji_reaction.status.account.user.settings['emoji_reactions.must_be_follower'] && !emoji_reaction.account.following?(emoji_reaction.status.account) end end diff --git a/app/views/admin/ng_words/show.html.haml b/app/views/admin/ng_words/show.html.haml index fe997df0e4..419a28b54d 100644 --- a/app/views/admin/ng_words/show.html.haml +++ b/app/views/admin/ng_words/show.html.haml @@ -10,5 +10,8 @@ .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 :enable_block_emoji_reaction_settings, wrapper: :with_label, as: :boolean, label: t('admin.ng_words.enable_block_emoji_reaction_settings') + .actions = f.button :button, t('generic.save_changes'), type: :submit diff --git a/app/views/settings/preferences/notifications/show.html.haml b/app/views/settings/preferences/notifications/show.html.haml index a87b765da9..2a7abb9488 100644 --- a/app/views/settings/preferences/notifications/show.html.haml +++ b/app/views/settings/preferences/notifications/show.html.haml @@ -33,9 +33,10 @@ = ff.input :'interactions.must_be_follower', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_follower') = ff.input :'interactions.must_be_following', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_following') = ff.input :'interactions.must_be_following_dm', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_following_dm') - = ff.input :'emoji_reactions.must_be_follower', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.must_be_follower') - = ff.input :'emoji_reactions.must_be_following', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.must_be_following') - = ff.input :'emoji_reactions.deny_from_all', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.deny_from_all') + - if Setting.enable_block_emoji_reaction_settings + = ff.input :'emoji_reactions.must_be_follower', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.must_be_follower') + = ff.input :'emoji_reactions.must_be_following', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.must_be_following') + = ff.input :'emoji_reactions.deny_from_all', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.deny_from_all') = f.simple_fields_for :settings, current_user.settings do |ff| .fields-group diff --git a/config/locales/en.yml b/config/locales/en.yml index 7e359ce134..5f280594b8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -596,6 +596,7 @@ en: media_attachments: title: Media attachments ng_words: + enable_block_emoji_reaction_settings: Enable block emoji reactions settings for users keywords: Reject keywords title: NG words and against spams relationships: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index afe8b5759f..bb6b6d263b 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -595,6 +595,7 @@ ja: media_attachments: title: 投稿された画像 ng_words: + enable_block_emoji_reaction_settings: 各ユーザーにスタンプ機能のブロック設定項目を解放する keywords: 投稿できないキーワード title: NGワードとスパム relationships: