2017-04-21 04:26:52 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UserSettingsDecorator
|
|
|
|
attr_reader :user, :settings
|
|
|
|
|
|
|
|
def initialize(user)
|
|
|
|
@user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(settings)
|
|
|
|
@settings = settings
|
|
|
|
process_update
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def process_update
|
2018-09-25 06:09:35 +03: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['boost_modal'] = boost_modal_preference if change?('setting_boost_modal')
|
2018-10-01 13:43:20 +03:00
|
|
|
user.settings['favourite_modal'] = favourite_modal_preference if change?('setting_favourite_modal')
|
2018-09-25 06:09:35 +03:00
|
|
|
user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal')
|
|
|
|
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')
|
2020-09-30 20:31:03 +03:00
|
|
|
user.settings['disable_swiping'] = disable_swiping_preference if change?('setting_disable_swiping')
|
2018-09-25 06:09:35 +03:00
|
|
|
user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui')
|
2019-08-12 16:31:20 +03:00
|
|
|
user.settings['system_emoji_font'] = system_emoji_font_preference if change?('setting_system_emoji_font')
|
2018-09-25 06:09:35 +03:00
|
|
|
user.settings['noindex'] = noindex_preference if change?('setting_noindex')
|
2022-11-05 12:55:25 +02:00
|
|
|
user.settings['hide_followers_count'] = hide_followers_count_preference if change?('setting_hide_followers_count')
|
2018-10-01 13:43:20 +03:00
|
|
|
user.settings['flavour'] = flavour_preference if change?('setting_flavour')
|
|
|
|
user.settings['skin'] = skin_preference if change?('setting_skin')
|
2023-02-04 12:26:59 +02:00
|
|
|
user.settings['norss'] = norss_preference if change?('setting_norss')
|
2018-12-09 14:03:01 +02:00
|
|
|
user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs')
|
2019-01-21 20:36:33 +02:00
|
|
|
user.settings['show_application'] = show_application_preference if change?('setting_show_application')
|
2019-05-25 22:27:00 +03:00
|
|
|
user.settings['advanced_layout'] = advanced_layout_preference if change?('setting_advanced_layout')
|
2019-05-13 15:42:39 +03:00
|
|
|
user.settings['default_content_type']= default_content_type_preference if change?('setting_default_content_type')
|
2019-06-26 20:33:04 +03:00
|
|
|
user.settings['use_blurhash'] = use_blurhash_preference if change?('setting_use_blurhash')
|
2019-07-16 07:30:47 +03:00
|
|
|
user.settings['use_pending_items'] = use_pending_items_preference if change?('setting_use_pending_items')
|
2019-08-06 18:57:52 +03:00
|
|
|
user.settings['trends'] = trends_preference if change?('setting_trends')
|
2019-10-24 23:51:41 +03:00
|
|
|
user.settings['crop_images'] = crop_images_preference if change?('setting_crop_images')
|
2022-11-30 16:59:37 +02:00
|
|
|
user.settings['visible_reactions'] = visible_reactions_preference if change?('setting_visible_reactions')
|
2022-04-08 19:03:31 +03:00
|
|
|
user.settings['always_send_emails'] = always_send_emails_preference if change?('setting_always_send_emails')
|
2017-04-21 04:26:52 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
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 15:00:32 +03:00
|
|
|
def default_sensitive_preference
|
|
|
|
boolean_cast_setting 'setting_default_sensitive'
|
|
|
|
end
|
|
|
|
|
2017-07-18 18:14:43 +03:00
|
|
|
def unfollow_modal_preference
|
|
|
|
boolean_cast_setting 'setting_unfollow_modal'
|
|
|
|
end
|
|
|
|
|
2017-04-21 04:26:52 +03:00
|
|
|
def boost_modal_preference
|
|
|
|
boolean_cast_setting 'setting_boost_modal'
|
|
|
|
end
|
|
|
|
|
2017-12-09 19:21:41 +02:00
|
|
|
def favourite_modal_preference
|
|
|
|
boolean_cast_setting 'setting_favourite_modal'
|
|
|
|
end
|
2017-04-21 04:26:52 +03:00
|
|
|
|
2017-05-29 18:56:13 +03:00
|
|
|
def delete_modal_preference
|
|
|
|
boolean_cast_setting 'setting_delete_modal'
|
|
|
|
end
|
|
|
|
|
2017-07-06 23:39:56 +03:00
|
|
|
def system_font_ui_preference
|
|
|
|
boolean_cast_setting 'setting_system_font_ui'
|
|
|
|
end
|
|
|
|
|
2019-08-12 16:31:20 +03:00
|
|
|
def system_emoji_font_preference
|
|
|
|
boolean_cast_setting 'setting_system_emoji_font'
|
|
|
|
end
|
|
|
|
|
2017-04-21 04:26:52 +03:00
|
|
|
def auto_play_gif_preference
|
|
|
|
boolean_cast_setting 'setting_auto_play_gif'
|
|
|
|
end
|
|
|
|
|
2018-09-25 06:09:35 +03:00
|
|
|
def display_media_preference
|
|
|
|
settings['setting_display_media']
|
2018-02-09 01:26:57 +02:00
|
|
|
end
|
|
|
|
|
2018-09-24 06:44:01 +03:00
|
|
|
def expand_spoilers_preference
|
|
|
|
boolean_cast_setting 'setting_expand_spoilers'
|
2018-02-09 01:26:57 +02:00
|
|
|
end
|
|
|
|
|
2017-10-16 10:36:15 +03:00
|
|
|
def reduce_motion_preference
|
|
|
|
boolean_cast_setting 'setting_reduce_motion'
|
|
|
|
end
|
|
|
|
|
2020-09-30 20:31:03 +03:00
|
|
|
def disable_swiping_preference
|
|
|
|
boolean_cast_setting 'setting_disable_swiping'
|
|
|
|
end
|
|
|
|
|
2017-07-14 17:41:02 +03:00
|
|
|
def noindex_preference
|
|
|
|
boolean_cast_setting 'setting_noindex'
|
|
|
|
end
|
|
|
|
|
2017-12-05 07:54:36 +02:00
|
|
|
def flavour_preference
|
|
|
|
settings['setting_flavour']
|
2017-09-26 05:24:32 +03:00
|
|
|
end
|
2017-12-01 05:29:47 +02:00
|
|
|
|
2023-02-04 12:26:59 +02:00
|
|
|
def norss_preference
|
|
|
|
boolean_cast_setting 'setting_norss'
|
|
|
|
end
|
|
|
|
|
2017-12-01 05:29:47 +02:00
|
|
|
def skin_preference
|
|
|
|
settings['setting_skin']
|
|
|
|
end
|
|
|
|
|
2022-11-05 12:55:25 +02:00
|
|
|
def hide_followers_count_preference
|
|
|
|
boolean_cast_setting 'setting_hide_followers_count'
|
|
|
|
end
|
|
|
|
|
2019-01-21 20:36:33 +02:00
|
|
|
def show_application_preference
|
|
|
|
boolean_cast_setting 'setting_show_application'
|
|
|
|
end
|
|
|
|
|
2018-06-17 19:57:31 +03:00
|
|
|
def default_language_preference
|
|
|
|
settings['setting_default_language']
|
|
|
|
end
|
|
|
|
|
2018-12-09 14:03:01 +02:00
|
|
|
def aggregate_reblogs_preference
|
|
|
|
boolean_cast_setting 'setting_aggregate_reblogs'
|
|
|
|
end
|
|
|
|
|
2019-05-25 22:27:00 +03:00
|
|
|
def advanced_layout_preference
|
|
|
|
boolean_cast_setting 'setting_advanced_layout'
|
|
|
|
end
|
|
|
|
|
2019-05-13 15:42:39 +03:00
|
|
|
def default_content_type_preference
|
|
|
|
settings['setting_default_content_type']
|
|
|
|
end
|
|
|
|
|
2019-06-26 20:33:04 +03:00
|
|
|
def use_blurhash_preference
|
|
|
|
boolean_cast_setting 'setting_use_blurhash'
|
|
|
|
end
|
|
|
|
|
2019-07-16 07:30:47 +03:00
|
|
|
def use_pending_items_preference
|
|
|
|
boolean_cast_setting 'setting_use_pending_items'
|
|
|
|
end
|
|
|
|
|
2019-08-06 18:57:52 +03:00
|
|
|
def trends_preference
|
|
|
|
boolean_cast_setting 'setting_trends'
|
|
|
|
end
|
|
|
|
|
2019-10-24 23:51:41 +03:00
|
|
|
def crop_images_preference
|
|
|
|
boolean_cast_setting 'setting_crop_images'
|
|
|
|
end
|
|
|
|
|
2022-11-30 16:59:37 +02:00
|
|
|
def visible_reactions_preference
|
2022-12-02 11:37:56 +02:00
|
|
|
integer_cast_setting('setting_visible_reactions', 0)
|
2022-11-30 16:59:37 +02:00
|
|
|
end
|
|
|
|
|
2022-04-08 19:03:31 +03:00
|
|
|
def always_send_emails_preference
|
|
|
|
boolean_cast_setting 'setting_always_send_emails'
|
|
|
|
end
|
|
|
|
|
2017-04-21 04:26:52 +03:00
|
|
|
def boolean_cast_setting(key)
|
2018-04-08 14:43:10 +03:00
|
|
|
ActiveModel::Type::Boolean.new.cast(settings[key])
|
2017-04-21 04:26:52 +03:00
|
|
|
end
|
|
|
|
|
2022-12-02 11:37:56 +02:00
|
|
|
def integer_cast_setting(key, min = nil, max = nil)
|
|
|
|
i = ActiveModel::Type::Integer.new.cast(settings[key])
|
2022-12-02 12:17:59 +02:00
|
|
|
# the cast above doesn't return a number if passed the string "e"
|
|
|
|
i = 0 unless i.is_a? Numeric
|
2022-12-02 11:37:56 +02:00
|
|
|
return min if !min.nil? && i < min
|
|
|
|
return max if !max.nil? && i > max
|
|
|
|
i
|
2022-11-30 16:59:37 +02:00
|
|
|
end
|
|
|
|
|
2017-04-21 04:26:52 +03:00
|
|
|
def coerced_settings(key)
|
|
|
|
coerce_values settings.fetch(key, {})
|
|
|
|
end
|
|
|
|
|
|
|
|
def coerce_values(params_hash)
|
2018-04-08 14:43:10 +03:00
|
|
|
params_hash.transform_values { |x| ActiveModel::Type::Boolean.new.cast(x) }
|
2017-04-21 04:26:52 +03:00
|
|
|
end
|
2017-10-04 11:22:52 +03:00
|
|
|
|
|
|
|
def change?(key)
|
|
|
|
!settings[key].nil?
|
|
|
|
end
|
2017-04-21 04:26:52 +03:00
|
|
|
end
|