From 2be77df3aaf486a25d7f2431f4644c1f9513b255 Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 13 Sep 2023 08:57:47 +0900 Subject: [PATCH] Add enable_emoji_reaction setting --- app/models/account.rb | 32 +++++++++++++------ app/models/form/admin_settings.rb | 2 ++ app/serializers/rest/account_serializer.rb | 2 +- .../admin/settings/discovery/show.html.haml | 5 +++ config/locales/en.yml | 1 + config/locales/ja.yml | 1 + config/locales/simple_form.en.yml | 1 + config/locales/simple_form.ja.yml | 1 + config/settings.yml | 1 + 9 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 8bee051b7a..4ad4fc0007 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -364,13 +364,16 @@ class Account < ApplicationRecord end def emoji_reaction_policy - return settings['emoji_reaction_policy']&.to_sym || :allow if settings.present? + return settings['emoji_reaction_policy']&.to_sym || :allow if settings.present? && user.nil? return :allow if user.nil? + return :block_and_hide if local? && !Setting.enable_emoji_reaction - user.settings&.[]('emoji_reaction_policy')&.to_sym + user.setting_emoji_reaction_policy&.to_sym end def show_emoji_reaction?(account) + return false unless Setting.enable_emoji_reaction + case emoji_reaction_policy when :block_and_hide false @@ -390,12 +393,7 @@ class Account < ApplicationRecord def allow_emoji_reaction?(account) return false if account.nil? - case emoji_reaction_policy - when :block - false - else - show_emoji_reaction?(account) - end + show_emoji_reaction?(account) end def public_settings @@ -408,12 +406,28 @@ class Account < ApplicationRecord 'hide_followers_count' => hide_followers_count?, 'translatable_private' => translatable_private?, 'link_preview' => link_preview?, - 'emoji_reaction_policy' => user&.setting_emoji_reaction_policy, } + if Setting.enable_emoji_reaction + config = config.merge({ + 'emoji_reaction_policy' => emoji_reaction_policy, + }) + end config = config.merge(settings) if settings.present? config end + def public_settings_for_local + config = public_settings + + unless Setting.enable_emoji_reaction + config = config.merge({ + 'emoji_reaction_policy' => :block_and_hide, + }) + end + + config + end + def previous_strikes_count strikes.where(overruled_at: nil).count end diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index a43ceb837e..606ad4b072 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -43,6 +43,7 @@ class Form::AdminSettings sensitive_words_for_full authorized_fetch receive_other_servers_emoji_reaction + enable_emoji_reaction ).freeze INTEGER_KEYS = %i( @@ -67,6 +68,7 @@ class Form::AdminSettings hide_local_users_for_anonymous authorized_fetch receive_other_servers_emoji_reaction + enable_emoji_reaction ).freeze UPLOAD_KEYS = %i( diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index 2574412136..772b71fe87 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -168,6 +168,6 @@ class REST::AccountSerializer < ActiveModel::Serializer end def other_settings - object.suspended? ? {} : object.public_settings + object.suspended? ? {} : object.public_settings_for_local end end diff --git a/app/views/admin/settings/discovery/show.html.haml b/app/views/admin/settings/discovery/show.html.haml index 0f4357c2db..99f8b50b4d 100644 --- a/app/views/admin/settings/discovery/show.html.haml +++ b/app/views/admin/settings/discovery/show.html.haml @@ -29,6 +29,11 @@ .fields-group = f.input :noindex, as: :boolean, wrapper: :with_label, label: t('admin.settings.default_noindex.title'), hint: t('admin.settings.default_noindex.desc_html') + %h4= t('admin.settings.discovery.emoji_reactions') + + .fields-group + = f.input :enable_emoji_reaction, as: :boolean, wrapper: :with_label, kmyblue: true, hint: false + .fields-group = f.input :receive_other_servers_emoji_reaction, as: :boolean, wrapper: :with_label, kmyblue: true diff --git a/config/locales/en.yml b/config/locales/en.yml index 42df586ddc..b84ee25ba1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -804,6 +804,7 @@ en: desc_html: Affects all users who have not changed this setting themselves title: Opt users out of search engine indexing by default discovery: + emoji_reactions: Stamp follow_recommendations: Follow recommendations preamble: Surfacing interesting content is instrumental in onboarding new users who may not know anyone Mastodon. Control how various discovery features work on your server. profile_directory: Profile directory diff --git a/config/locales/ja.yml b/config/locales/ja.yml index cffaf229a3..2e344602ab 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -800,6 +800,7 @@ ja: desc_html: この設定を自分で変更していない全ユーザーに影響します title: デフォルトで検索エンジンによるインデックスを拒否する discovery: + emoji_reactions: スタンプ follow_recommendations: おすすめフォロー preamble: Mastodon を知らないユーザーを取り込むには、興味深いコンテンツを浮上させることが重要です。サーバー上で様々なディスカバリー機能がどのように機能するかを制御します。 profile_directory: ディレクトリ diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 93c6f47a48..ca96aa3861 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -314,6 +314,7 @@ en: closed_registrations_message: Custom message when sign-ups are not available content_cache_retention_period: Content cache retention period custom_css: Custom CSS + enable_emoji_reaction: Enable stamp function mascot: Custom mascot (legacy) media_cache_retention_period: Media cache retention period peers_api_enabled: Publish list of discovered servers in the API diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index def4e311c5..b217436a74 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -325,6 +325,7 @@ ja: closed_registrations_message: アカウント作成を停止している時のカスタムメッセージ content_cache_retention_period: コンテンツキャッシュの保持期間 custom_css: カスタムCSS + enable_emoji_reaction: スタンプ機能を有効にする mascot: カスタムマスコット(レガシー) media_cache_retention_period: メディアキャッシュの保持期間 peers_api_enabled: 発見したサーバーのリストをAPIで公開する diff --git a/config/settings.yml b/config/settings.yml index a9c4313164..805fe02407 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -39,6 +39,7 @@ defaults: &defaults backups_retention_period: 7 captcha_enabled: false receive_other_servers_emoji_reaction: false + enable_emoji_reaction: true development: <<: *defaults