2017-04-21 01:26:52 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UserSettingsDecorator
|
|
|
|
attr_reader :user, :settings
|
|
|
|
|
|
|
|
def initialize(user)
|
|
|
|
@user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(settings)
|
|
|
|
@settings = settings
|
|
|
|
process_update
|
2022-02-08 04:50:44 +00:00
|
|
|
profile_change?
|
2017-04-21 01:26:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-02-08 04:50:44 +00:00
|
|
|
PROFILE_KEYS = %w(
|
|
|
|
setting_noindex
|
|
|
|
setting_hide_network
|
|
|
|
setting_hide_statuses_count
|
|
|
|
setting_hide_following_count
|
|
|
|
setting_hide_followers_count
|
|
|
|
setting_enable_reaction
|
|
|
|
).freeze
|
|
|
|
|
|
|
|
def profile_change?
|
|
|
|
settings.keys.intersection(PROFILE_KEYS).any?
|
|
|
|
end
|
|
|
|
|
2017-04-21 01:26:52 +00:00
|
|
|
def process_update
|
2020-01-11 11:24:22 +00:00
|
|
|
user.settings['notification_emails'] = merged_notification_emails if change?('notification_emails')
|
|
|
|
user.settings['interactions'] = merged_interactions if change?('interactions')
|
|
|
|
user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy')
|
|
|
|
user.settings['default_sensitive'] = default_sensitive_preference if change?('setting_default_sensitive')
|
|
|
|
user.settings['default_language'] = default_language_preference if change?('setting_default_language')
|
|
|
|
user.settings['unfollow_modal'] = unfollow_modal_preference if change?('setting_unfollow_modal')
|
|
|
|
user.settings['unsubscribe_modal'] = unsubscribe_modal_preference if change?('setting_unsubscribe_modal')
|
|
|
|
user.settings['boost_modal'] = boost_modal_preference if change?('setting_boost_modal')
|
|
|
|
user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal')
|
2022-03-17 14:25:16 +00:00
|
|
|
user.settings['post_reference_modal'] = post_reference_modal_preference if change?('setting_post_reference_modal')
|
|
|
|
user.settings['add_reference_modal'] = add_reference_modal_preference if change?('setting_add_reference_modal')
|
|
|
|
user.settings['unselect_reference_modal'] = unselect_reference_modal_preference if change?('setting_unselect_reference_modal')
|
2020-01-11 11:24:22 +00:00
|
|
|
user.settings['auto_play_gif'] = auto_play_gif_preference if change?('setting_auto_play_gif')
|
|
|
|
user.settings['display_media'] = display_media_preference if change?('setting_display_media')
|
|
|
|
user.settings['expand_spoilers'] = expand_spoilers_preference if change?('setting_expand_spoilers')
|
|
|
|
user.settings['reduce_motion'] = reduce_motion_preference if change?('setting_reduce_motion')
|
|
|
|
user.settings['disable_swiping'] = disable_swiping_preference if change?('setting_disable_swiping')
|
|
|
|
user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui')
|
|
|
|
user.settings['noindex'] = noindex_preference if change?('setting_noindex')
|
|
|
|
user.settings['theme'] = theme_preference if change?('setting_theme')
|
|
|
|
user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network')
|
|
|
|
user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs')
|
|
|
|
user.settings['show_application'] = show_application_preference if change?('setting_show_application')
|
|
|
|
user.settings['advanced_layout'] = advanced_layout_preference if change?('setting_advanced_layout')
|
|
|
|
user.settings['use_blurhash'] = use_blurhash_preference if change?('setting_use_blurhash')
|
|
|
|
user.settings['use_pending_items'] = use_pending_items_preference if change?('setting_use_pending_items')
|
|
|
|
user.settings['trends'] = trends_preference if change?('setting_trends')
|
|
|
|
user.settings['crop_images'] = crop_images_preference if change?('setting_crop_images')
|
|
|
|
user.settings['show_follow_button_on_timeline'] = show_follow_button_on_timeline_preference if change?('setting_show_follow_button_on_timeline')
|
|
|
|
user.settings['show_subscribe_button_on_timeline'] = show_subscribe_button_on_timeline_preference if change?('setting_show_subscribe_button_on_timeline')
|
2020-03-21 04:25:30 +00:00
|
|
|
user.settings['show_followed_by'] = show_followed_by_preference if change?('setting_show_followed_by')
|
|
|
|
user.settings['follow_button_to_list_adder'] = follow_button_to_list_adder_preference if change?('setting_follow_button_to_list_adder')
|
2019-07-08 04:03:08 +00:00
|
|
|
user.settings['show_navigation_panel'] = show_navigation_panel_preference if change?('setting_show_navigation_panel')
|
2020-07-01 10:05:49 +00:00
|
|
|
user.settings['show_quote_button'] = show_quote_button_preference if change?('setting_show_quote_button')
|
|
|
|
user.settings['show_bookmark_button'] = show_bookmark_button_preference if change?('setting_show_bookmark_button')
|
2020-01-11 11:24:22 +00:00
|
|
|
user.settings['show_target'] = show_target_preference if change?('setting_show_target')
|
2021-01-27 22:45:40 +00:00
|
|
|
user.settings['place_tab_bar_at_bottom'] = place_tab_bar_at_bottom_preference if change?('setting_place_tab_bar_at_bottom')
|
|
|
|
user.settings['show_tab_bar_label'] = show_tab_bar_label_preference if change?('setting_show_tab_bar_label')
|
2021-04-12 12:43:25 +00:00
|
|
|
user.settings['enable_limited_timeline'] = enable_limited_timeline_preference if change?('setting_enable_limited_timeline')
|
2021-05-19 05:58:27 +00:00
|
|
|
user.settings['enable_reaction'] = enable_reaction_preference if change?('setting_enable_reaction')
|
2022-06-01 13:43:20 +00:00
|
|
|
user.settings['compact_reaction'] = compact_reaction_preference if change?('setting_compact_reaction')
|
2021-06-19 15:06:49 +00:00
|
|
|
user.settings['show_reply_tree_button'] = show_reply_tree_button_preference if change?('setting_show_reply_tree_button')
|
2022-02-08 04:50:44 +00:00
|
|
|
user.settings['hide_statuses_count'] = hide_statuses_count_preference if change?('setting_hide_statuses_count')
|
|
|
|
user.settings['hide_following_count'] = hide_following_count_preference if change?('setting_hide_following_count')
|
|
|
|
user.settings['hide_followers_count'] = hide_followers_count_preference if change?('setting_hide_followers_count')
|
2022-02-09 20:47:09 +00:00
|
|
|
user.settings['disable_joke_appearance'] = disable_joke_appearance_preference if change?('setting_disable_joke_appearance')
|
2022-02-16 09:55:06 +00:00
|
|
|
user.settings['new_features_policy'] = new_features_policy if change?('setting_new_features_policy')
|
2022-02-20 21:32:59 +00:00
|
|
|
user.settings['theme_instance_ticker'] = theme_instance_ticker if change?('setting_theme_instance_ticker')
|
2022-03-17 14:25:16 +00:00
|
|
|
user.settings['enable_status_reference'] = enable_status_reference_preference if change?('setting_enable_status_reference')
|
|
|
|
user.settings['match_visibility_of_references'] = match_visibility_of_references_preference if change?('setting_match_visibility_of_references')
|
2022-03-21 10:19:57 +00:00
|
|
|
user.settings['hexagon_avatar'] = hexagon_avatar_preference if change?('setting_hexagon_avatar')
|
2022-05-19 10:22:49 +00:00
|
|
|
user.settings['enable_empty_column'] = enable_empty_column_preference if change?('setting_enable_empty_column')
|
2022-06-02 06:46:38 +00:00
|
|
|
user.settings['content_font_size'] = content_font_size_preference if change?('setting_content_font_size')
|
|
|
|
user.settings['info_font_size'] = info_font_size_preference if change?('setting_info_font_size')
|
|
|
|
user.settings['content_emoji_reaction_size'] = content_emoji_reaction_size_preference if change?('setting_content_emoji_reaction_size')
|
2022-03-17 14:25:16 +00:00
|
|
|
end
|
2017-04-21 01:26:52 +00:00
|
|
|
|
|
|
|
def merged_notification_emails
|
|
|
|
user.settings['notification_emails'].merge coerced_settings('notification_emails').to_h
|
|
|
|
end
|
|
|
|
|
|
|
|
def merged_interactions
|
|
|
|
user.settings['interactions'].merge coerced_settings('interactions').to_h
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_privacy_preference
|
|
|
|
settings['setting_default_privacy']
|
|
|
|
end
|
|
|
|
|
2017-07-10 12:00:32 +00:00
|
|
|
def default_sensitive_preference
|
|
|
|
boolean_cast_setting 'setting_default_sensitive'
|
|
|
|
end
|
|
|
|
|
2017-07-18 15:14:43 +00:00
|
|
|
def unfollow_modal_preference
|
|
|
|
boolean_cast_setting 'setting_unfollow_modal'
|
|
|
|
end
|
|
|
|
|
2019-12-12 11:02:35 +00:00
|
|
|
def unsubscribe_modal_preference
|
|
|
|
boolean_cast_setting 'setting_unsubscribe_modal'
|
|
|
|
end
|
|
|
|
|
2017-04-21 01:26:52 +00:00
|
|
|
def boost_modal_preference
|
|
|
|
boolean_cast_setting 'setting_boost_modal'
|
|
|
|
end
|
|
|
|
|
2017-05-29 15:56:13 +00:00
|
|
|
def delete_modal_preference
|
|
|
|
boolean_cast_setting 'setting_delete_modal'
|
|
|
|
end
|
|
|
|
|
2022-03-17 14:25:16 +00:00
|
|
|
def post_reference_modal_preference
|
|
|
|
boolean_cast_setting 'setting_post_reference_modal'
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_reference_modal_preference
|
|
|
|
boolean_cast_setting 'setting_add_reference_modal'
|
|
|
|
end
|
|
|
|
|
|
|
|
def unselect_reference_modal_preference
|
|
|
|
boolean_cast_setting 'setting_unselect_reference_modal'
|
|
|
|
end
|
|
|
|
|
2017-07-06 20:39:56 +00:00
|
|
|
def system_font_ui_preference
|
|
|
|
boolean_cast_setting 'setting_system_font_ui'
|
|
|
|
end
|
|
|
|
|
2017-04-21 01:26:52 +00:00
|
|
|
def auto_play_gif_preference
|
|
|
|
boolean_cast_setting 'setting_auto_play_gif'
|
|
|
|
end
|
|
|
|
|
2018-09-25 03:09:35 +00:00
|
|
|
def display_media_preference
|
|
|
|
settings['setting_display_media']
|
2018-02-08 23:26:57 +00:00
|
|
|
end
|
|
|
|
|
2018-09-24 03:44:01 +00:00
|
|
|
def expand_spoilers_preference
|
|
|
|
boolean_cast_setting 'setting_expand_spoilers'
|
|
|
|
end
|
|
|
|
|
2017-10-16 07:36:15 +00:00
|
|
|
def reduce_motion_preference
|
|
|
|
boolean_cast_setting 'setting_reduce_motion'
|
|
|
|
end
|
|
|
|
|
2020-09-30 17:31:03 +00:00
|
|
|
def disable_swiping_preference
|
|
|
|
boolean_cast_setting 'setting_disable_swiping'
|
|
|
|
end
|
|
|
|
|
2017-07-14 14:41:02 +00:00
|
|
|
def noindex_preference
|
|
|
|
boolean_cast_setting 'setting_noindex'
|
|
|
|
end
|
|
|
|
|
2018-05-18 00:26:51 +00:00
|
|
|
def hide_network_preference
|
|
|
|
boolean_cast_setting 'setting_hide_network'
|
|
|
|
end
|
|
|
|
|
2019-02-02 18:18:15 +00:00
|
|
|
def show_application_preference
|
|
|
|
boolean_cast_setting 'setting_show_application'
|
|
|
|
end
|
|
|
|
|
2017-09-19 14:36:23 +00:00
|
|
|
def theme_preference
|
|
|
|
settings['setting_theme']
|
|
|
|
end
|
|
|
|
|
2018-06-17 16:57:31 +00:00
|
|
|
def default_language_preference
|
|
|
|
settings['setting_default_language']
|
|
|
|
end
|
|
|
|
|
2018-12-09 12:03:01 +00:00
|
|
|
def aggregate_reblogs_preference
|
|
|
|
boolean_cast_setting 'setting_aggregate_reblogs'
|
|
|
|
end
|
|
|
|
|
2019-05-25 19:27:00 +00:00
|
|
|
def advanced_layout_preference
|
|
|
|
boolean_cast_setting 'setting_advanced_layout'
|
|
|
|
end
|
|
|
|
|
2019-06-26 17:33:04 +00:00
|
|
|
def use_blurhash_preference
|
|
|
|
boolean_cast_setting 'setting_use_blurhash'
|
|
|
|
end
|
|
|
|
|
2019-07-16 04:30:47 +00:00
|
|
|
def use_pending_items_preference
|
|
|
|
boolean_cast_setting 'setting_use_pending_items'
|
|
|
|
end
|
|
|
|
|
2019-08-06 15:57:52 +00:00
|
|
|
def trends_preference
|
|
|
|
boolean_cast_setting 'setting_trends'
|
|
|
|
end
|
|
|
|
|
2019-10-24 20:51:41 +00:00
|
|
|
def crop_images_preference
|
|
|
|
boolean_cast_setting 'setting_crop_images'
|
|
|
|
end
|
|
|
|
|
2020-01-11 11:24:22 +00:00
|
|
|
def show_follow_button_on_timeline_preference
|
|
|
|
boolean_cast_setting 'setting_show_follow_button_on_timeline'
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_subscribe_button_on_timeline_preference
|
|
|
|
boolean_cast_setting 'setting_show_subscribe_button_on_timeline'
|
|
|
|
end
|
|
|
|
|
2020-03-21 04:25:30 +00:00
|
|
|
def show_followed_by_preference
|
|
|
|
boolean_cast_setting 'setting_show_followed_by'
|
|
|
|
end
|
|
|
|
|
|
|
|
def follow_button_to_list_adder_preference
|
|
|
|
boolean_cast_setting 'setting_follow_button_to_list_adder'
|
|
|
|
end
|
|
|
|
|
2019-07-08 04:03:08 +00:00
|
|
|
def show_navigation_panel_preference
|
|
|
|
boolean_cast_setting 'setting_show_navigation_panel'
|
|
|
|
end
|
|
|
|
|
2020-07-01 10:05:49 +00:00
|
|
|
def show_quote_button_preference
|
|
|
|
boolean_cast_setting 'setting_show_quote_button'
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_bookmark_button_preference
|
|
|
|
boolean_cast_setting 'setting_show_bookmark_button'
|
|
|
|
end
|
|
|
|
|
2020-01-11 11:24:22 +00:00
|
|
|
def show_target_preference
|
|
|
|
boolean_cast_setting 'setting_show_target'
|
|
|
|
end
|
|
|
|
|
2021-01-27 22:45:40 +00:00
|
|
|
def place_tab_bar_at_bottom_preference
|
|
|
|
boolean_cast_setting 'setting_place_tab_bar_at_bottom'
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_tab_bar_label_preference
|
|
|
|
boolean_cast_setting 'setting_show_tab_bar_label'
|
|
|
|
end
|
|
|
|
|
2021-04-12 12:43:25 +00:00
|
|
|
def enable_limited_timeline_preference
|
|
|
|
boolean_cast_setting 'setting_enable_limited_timeline'
|
|
|
|
end
|
|
|
|
|
2021-05-19 05:58:27 +00:00
|
|
|
def enable_reaction_preference
|
|
|
|
boolean_cast_setting 'setting_enable_reaction'
|
|
|
|
end
|
|
|
|
|
2022-06-01 13:43:20 +00:00
|
|
|
def compact_reaction_preference
|
|
|
|
boolean_cast_setting 'setting_compact_reaction'
|
|
|
|
end
|
|
|
|
|
2021-06-19 15:06:49 +00:00
|
|
|
def show_reply_tree_button_preference
|
|
|
|
boolean_cast_setting 'setting_show_reply_tree_button'
|
|
|
|
end
|
|
|
|
|
2022-02-08 04:50:44 +00:00
|
|
|
def hide_statuses_count_preference
|
|
|
|
boolean_cast_setting 'setting_hide_statuses_count'
|
|
|
|
end
|
|
|
|
|
|
|
|
def hide_following_count_preference
|
|
|
|
boolean_cast_setting 'setting_hide_following_count'
|
|
|
|
end
|
|
|
|
|
|
|
|
def hide_followers_count_preference
|
|
|
|
boolean_cast_setting 'setting_hide_followers_count'
|
|
|
|
end
|
|
|
|
|
2022-02-09 20:47:09 +00:00
|
|
|
def disable_joke_appearance_preference
|
|
|
|
boolean_cast_setting 'setting_disable_joke_appearance'
|
|
|
|
end
|
|
|
|
|
2022-02-16 09:55:06 +00:00
|
|
|
def new_features_policy
|
|
|
|
settings['setting_new_features_policy']
|
|
|
|
end
|
|
|
|
|
2022-02-20 21:32:59 +00:00
|
|
|
def theme_instance_ticker
|
|
|
|
settings['setting_theme_instance_ticker']
|
|
|
|
end
|
|
|
|
|
2022-03-21 10:19:57 +00:00
|
|
|
def hexagon_avatar_preference
|
|
|
|
boolean_cast_setting 'setting_hexagon_avatar'
|
|
|
|
end
|
|
|
|
|
2022-03-17 14:25:16 +00:00
|
|
|
def enable_status_reference_preference
|
|
|
|
boolean_cast_setting 'setting_enable_status_reference'
|
|
|
|
end
|
|
|
|
|
|
|
|
def match_visibility_of_references_preference
|
|
|
|
boolean_cast_setting 'setting_match_visibility_of_references'
|
|
|
|
end
|
|
|
|
|
2022-05-19 10:22:49 +00:00
|
|
|
def enable_empty_column_preference
|
|
|
|
boolean_cast_setting 'setting_enable_empty_column'
|
|
|
|
end
|
|
|
|
|
2022-06-02 06:46:38 +00:00
|
|
|
def content_font_size_preference
|
|
|
|
settings['setting_content_font_size']
|
|
|
|
end
|
|
|
|
|
|
|
|
def info_font_size_preference
|
|
|
|
settings['setting_info_font_size']
|
|
|
|
end
|
|
|
|
|
|
|
|
def content_emoji_reaction_size_preference
|
|
|
|
settings['setting_content_emoji_reaction_size']
|
|
|
|
end
|
|
|
|
|
2017-04-21 01:26:52 +00:00
|
|
|
def boolean_cast_setting(key)
|
2018-04-08 11:43:10 +00:00
|
|
|
ActiveModel::Type::Boolean.new.cast(settings[key])
|
2017-04-21 01:26:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def coerced_settings(key)
|
|
|
|
coerce_values settings.fetch(key, {})
|
|
|
|
end
|
|
|
|
|
|
|
|
def coerce_values(params_hash)
|
2018-04-08 11:43:10 +00:00
|
|
|
params_hash.transform_values { |x| ActiveModel::Type::Boolean.new.cast(x) }
|
2017-04-21 01:26:52 +00:00
|
|
|
end
|
2017-10-04 08:22:52 +00:00
|
|
|
|
|
|
|
def change?(key)
|
|
|
|
!settings[key].nil?
|
|
|
|
end
|
2017-04-21 01:26:52 +00:00
|
|
|
end
|