mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-26 02:01:36 +01:00
Reduce AbcSize complexity in InitialStateSerializer
(#27782)
This commit is contained in:
parent
1f1c75bba5
commit
35deaaf90b
2 changed files with 29 additions and 21 deletions
|
@ -26,7 +26,7 @@ Lint/NonLocalExitFromIterator:
|
||||||
|
|
||||||
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Max: 144
|
Max: 125
|
||||||
|
|
||||||
# Configuration parameters: CountBlocks, Max.
|
# Configuration parameters: CountBlocks, Max.
|
||||||
Metrics/BlockNesting:
|
Metrics/BlockNesting:
|
||||||
|
|
|
@ -39,18 +39,18 @@ class InitialStateSerializer < ActiveModel::Serializer
|
||||||
|
|
||||||
if object.current_account
|
if object.current_account
|
||||||
store[:me] = object.current_account.id.to_s
|
store[:me] = object.current_account.id.to_s
|
||||||
store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal
|
store[:unfollow_modal] = object_account_user.setting_unfollow_modal
|
||||||
store[:boost_modal] = object.current_account.user.setting_boost_modal
|
store[:boost_modal] = object_account_user.setting_boost_modal
|
||||||
store[:delete_modal] = object.current_account.user.setting_delete_modal
|
store[:delete_modal] = object_account_user.setting_delete_modal
|
||||||
store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
|
store[:auto_play_gif] = object_account_user.setting_auto_play_gif
|
||||||
store[:display_media] = object.current_account.user.setting_display_media
|
store[:display_media] = object_account_user.setting_display_media
|
||||||
store[:expand_spoilers] = object.current_account.user.setting_expand_spoilers
|
store[:expand_spoilers] = object_account_user.setting_expand_spoilers
|
||||||
store[:reduce_motion] = object.current_account.user.setting_reduce_motion
|
store[:reduce_motion] = object_account_user.setting_reduce_motion
|
||||||
store[:disable_swiping] = object.current_account.user.setting_disable_swiping
|
store[:disable_swiping] = object_account_user.setting_disable_swiping
|
||||||
store[:advanced_layout] = object.current_account.user.setting_advanced_layout
|
store[:advanced_layout] = object_account_user.setting_advanced_layout
|
||||||
store[:use_blurhash] = object.current_account.user.setting_use_blurhash
|
store[:use_blurhash] = object_account_user.setting_use_blurhash
|
||||||
store[:use_pending_items] = object.current_account.user.setting_use_pending_items
|
store[:use_pending_items] = object_account_user.setting_use_pending_items
|
||||||
store[:show_trends] = Setting.trends && object.current_account.user.setting_trends
|
store[:show_trends] = Setting.trends && object_account_user.setting_trends
|
||||||
else
|
else
|
||||||
store[:auto_play_gif] = Setting.auto_play_gif
|
store[:auto_play_gif] = Setting.auto_play_gif
|
||||||
store[:display_media] = Setting.display_media
|
store[:display_media] = Setting.display_media
|
||||||
|
@ -71,9 +71,9 @@ class InitialStateSerializer < ActiveModel::Serializer
|
||||||
|
|
||||||
if object.current_account
|
if object.current_account
|
||||||
store[:me] = object.current_account.id.to_s
|
store[:me] = object.current_account.id.to_s
|
||||||
store[:default_privacy] = object.visibility || object.current_account.user.setting_default_privacy
|
store[:default_privacy] = object.visibility || object_account_user.setting_default_privacy
|
||||||
store[:default_sensitive] = object.current_account.user.setting_default_sensitive
|
store[:default_sensitive] = object_account_user.setting_default_sensitive
|
||||||
store[:default_language] = object.current_account.user.preferred_posting_language
|
store[:default_language] = object_account_user.preferred_posting_language
|
||||||
end
|
end
|
||||||
|
|
||||||
store[:text] = object.text if object.text
|
store[:text] = object.text if object.text
|
||||||
|
@ -89,11 +89,11 @@ class InitialStateSerializer < ActiveModel::Serializer
|
||||||
associations: [:account_stat, :user, { moved_to_account: [:account_stat, :user] }]
|
associations: [:account_stat, :user, { moved_to_account: [:account_stat, :user] }]
|
||||||
)
|
)
|
||||||
|
|
||||||
store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
|
store[object.current_account.id.to_s] = serialized_account(object.current_account) if object.current_account
|
||||||
store[object.admin.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
|
store[object.admin.id.to_s] = serialized_account(object.admin) if object.admin
|
||||||
store[object.owner.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.owner, serializer: REST::AccountSerializer) if object.owner
|
store[object.owner.id.to_s] = serialized_account(object.owner) if object.owner
|
||||||
store[object.disabled_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.disabled_account, serializer: REST::AccountSerializer) if object.disabled_account
|
store[object.disabled_account.id.to_s] = serialized_account(object.disabled_account) if object.disabled_account
|
||||||
store[object.moved_to_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.moved_to_account, serializer: REST::AccountSerializer) if object.moved_to_account
|
store[object.moved_to_account.id.to_s] = serialized_account(object.moved_to_account) if object.moved_to_account
|
||||||
|
|
||||||
store
|
store
|
||||||
end
|
end
|
||||||
|
@ -108,6 +108,14 @@ class InitialStateSerializer < ActiveModel::Serializer
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def object_account_user
|
||||||
|
object.current_account.user
|
||||||
|
end
|
||||||
|
|
||||||
|
def serialized_account(account)
|
||||||
|
ActiveModelSerializers::SerializableResource.new(account, serializer: REST::AccountSerializer)
|
||||||
|
end
|
||||||
|
|
||||||
def instance_presenter
|
def instance_presenter
|
||||||
@instance_presenter ||= InstancePresenter.new
|
@instance_presenter ||= InstancePresenter.new
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue