Refactor: #160 アカウントのother_settings関連部分を別ファイルに切り出し (#176)

* Bump version to 8.0

* Add: 他のサーバーに公開する情報に、制限設定などを追加

* Fix: `quote_of_id`のインデックス

* Fix: #172 他のサーバーからの相乗り絵文字削除が反映されない

* Test: #166 リモートから自分の絵文字を受け取った時、ライセンスが上書きされないことを確認するテスト

* Refactor: #160 アカウントの`other_settings`関連部分を別ファイルに切り出し
This commit is contained in:
KMY(雪あすか) 2023-10-26 10:06:47 +09:00 committed by GitHub
parent 952ea84868
commit 3caa413e23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 123 additions and 115 deletions

View file

@ -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

View file

@ -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