From 3caa413e23c2e67b32ae38c300bcfd7eb2d75605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Thu, 26 Oct 2023 10:06:47 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20#160=20=E3=82=A2=E3=82=AB=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=AEother=5Fsettings=E9=96=A2=E9=80=A3?= =?UTF-8?q?=E9=83=A8=E5=88=86=E3=82=92=E5=88=A5=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=AB=E5=88=87=E3=82=8A=E5=87=BA=E3=81=97=20(#176)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Bump version to 8.0 * Add: 他のサーバーに公開する情報に、制限設定などを追加 * Fix: `quote_of_id`のインデックス * Fix: #172 他のサーバーからの相乗り絵文字削除が反映されない * Test: #166 リモートから自分の絵文字を受け取った時、ライセンスが上書きされないことを確認するテスト * Refactor: #160 アカウントの`other_settings`関連部分を別ファイルに切り出し --- app/models/account.rb | 116 +---------------- app/models/concerns/account_other_settings.rb | 122 ++++++++++++++++++ 2 files changed, 123 insertions(+), 115 deletions(-) create mode 100644 app/models/concerns/account_other_settings.rb diff --git a/app/models/account.rb b/app/models/account.rb index 7170cbe1e2..b05ef3c1ad 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -87,6 +87,7 @@ class Account < ApplicationRecord include AccountMerging include AccountSearch include AccountStatusesSearch + include AccountOtherSettings enum protocol: { ostatus: 0, activitypub: 1 } enum suspension_origin: { local: 0, remote: 1 }, _prefix: true @@ -311,32 +312,6 @@ class Account < ApplicationRecord true end - def noindex? - user_prefers_noindex? || (settings.present? && settings['noindex']) || false - end - - def noai? - user&.setting_noai || (settings.present? && settings['noai']) || false - end - - def translatable_private? - user&.setting_translatable_private || (settings.present? && settings['translatable_private']) || false - end - - def link_preview? - return user.setting_link_preview if local? && user.present? - return settings['link_preview'] if settings.present? && settings.key?('link_preview') - - true - end - - def allow_quote? - return user.setting_allow_quote if local? && user.present? - return settings['allow_quote'] if settings.present? && settings.key?('allow_quote') - - true - end - def public_statuses_count hide_statuses_count? ? 0 : statuses_count end @@ -349,95 +324,6 @@ class Account < ApplicationRecord hide_followers_count? ? 0 : followers_count end - def hide_statuses_count? - return user&.setting_hide_statuses_count unless user&.setting_hide_statuses_count.nil? - return settings['hide_statuses_count'] if settings.present? - - false - end - - def hide_following_count? - return user&.setting_hide_following_count unless user&.setting_hide_following_count.nil? - return settings['hide_following_count'] if settings.present? - - false - end - - def hide_followers_count? - return user&.setting_hide_followers_count unless user&.setting_hide_followers_count.nil? - return settings['hide_followers_count'] if settings.present? - - false - end - - def emoji_reaction_policy - return settings['emoji_reaction_policy']&.to_sym || :allow if settings.present? && user.nil? - return :allow if user.nil? - return :block if local? && !Setting.enable_emoji_reaction - - 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 - false - when :following_only - account.present? && (id == account.id || following?(account)) - when :followers_only - account.present? && (id == account.id || followed_by?(account)) - when :mutuals_only - account.present? && (id == account.id || mutual?(account)) - when :outside_only - account.present? && (id == account.id || following?(account) || followed_by?(account)) - else - true - end - end - - def allow_emoji_reaction?(account) - return false if account.nil? - return true unless local? || account.local? - - show_emoji_reaction?(account) - end - - def public_settings - # Please update `app/javascript/mastodon/api_types/accounts.ts` when making changes to the attributes - config = { - 'noindex' => noindex?, - 'noai' => noai?, - 'hide_network' => hide_collections, - 'hide_statuses_count' => hide_statuses_count?, - 'hide_following_count' => hide_following_count?, - 'hide_followers_count' => hide_followers_count?, - 'translatable_private' => translatable_private?, - 'link_preview' => link_preview?, - 'allow_quote' => allow_quote?, - } - 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, - }) - end - - config - end - def previous_strikes_count strikes.where(overruled_at: nil).count end diff --git a/app/models/concerns/account_other_settings.rb b/app/models/concerns/account_other_settings.rb new file mode 100644 index 0000000000..a4655e5b72 --- /dev/null +++ b/app/models/concerns/account_other_settings.rb @@ -0,0 +1,122 @@ +# frozen_string_literal: true + +module AccountOtherSettings + extend ActiveSupport::Concern + + included do + def noindex? + user_prefers_noindex? || (settings.present? && settings['noindex']) || false + end + + def noai? + user&.setting_noai || (settings.present? && settings['noai']) || false + end + + def translatable_private? + user&.setting_translatable_private || (settings.present? && settings['translatable_private']) || false + end + + def link_preview? + return user.setting_link_preview if local? && user.present? + return settings['link_preview'] if settings.present? && settings.key?('link_preview') + + true + end + + def allow_quote? + return user.setting_allow_quote if local? && user.present? + return settings['allow_quote'] if settings.present? && settings.key?('allow_quote') + + true + end + + def hide_statuses_count? + return user&.setting_hide_statuses_count unless user&.setting_hide_statuses_count.nil? + return settings['hide_statuses_count'] if settings.present? + + false + end + + def hide_following_count? + return user&.setting_hide_following_count unless user&.setting_hide_following_count.nil? + return settings['hide_following_count'] if settings.present? + + false + end + + def hide_followers_count? + return user&.setting_hide_followers_count unless user&.setting_hide_followers_count.nil? + return settings['hide_followers_count'] if settings.present? + + false + end + + def emoji_reaction_policy + return settings['emoji_reaction_policy']&.to_sym || :allow if settings.present? && user.nil? + return :allow if user.nil? + return :block if local? && !Setting.enable_emoji_reaction + + 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 + false + when :following_only + account.present? && (id == account.id || following?(account)) + when :followers_only + account.present? && (id == account.id || followed_by?(account)) + when :mutuals_only + account.present? && (id == account.id || mutual?(account)) + when :outside_only + account.present? && (id == account.id || following?(account) || followed_by?(account)) + else + true + end + end + + def allow_emoji_reaction?(account) + return false if account.nil? + return true unless local? || account.local? + + show_emoji_reaction?(account) + end + + def public_settings + # Please update `app/javascript/mastodon/api_types/accounts.ts` when making changes to the attributes + config = { + 'noindex' => noindex?, + 'noai' => noai?, + 'hide_network' => hide_collections, + 'hide_statuses_count' => hide_statuses_count?, + 'hide_following_count' => hide_following_count?, + 'hide_followers_count' => hide_followers_count?, + 'translatable_private' => translatable_private?, + 'link_preview' => link_preview?, + 'allow_quote' => allow_quote?, + } + 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, + }) + end + + config + end + end +end