2023-03-30 05:44:00 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UserSettings
|
|
|
|
class Error < StandardError; end
|
|
|
|
class KeyError < Error; end
|
|
|
|
|
|
|
|
include UserSettings::DSL
|
|
|
|
include UserSettings::Glue
|
|
|
|
|
|
|
|
setting :always_send_emails, default: false
|
|
|
|
setting :aggregate_reblogs, default: true
|
2023-03-31 12:37:57 -07:00
|
|
|
setting :flavour, default: -> { ::Setting.flavour }
|
|
|
|
setting :skin, default: -> { ::Setting.skin }
|
2023-03-30 05:44:00 -07:00
|
|
|
setting :noindex, default: -> { ::Setting.noindex }
|
|
|
|
setting :show_application, default: true
|
|
|
|
setting :default_language, default: nil
|
|
|
|
setting :default_sensitive, default: false
|
2023-06-20 09:32:14 -07:00
|
|
|
setting :default_privacy, default: nil, in: %w(public unlisted private)
|
2023-03-31 12:37:57 -07:00
|
|
|
setting :default_content_type, default: 'text/plain'
|
|
|
|
setting :hide_followers_count, default: false
|
2023-03-30 05:44:00 -07:00
|
|
|
|
2023-08-14 09:52:45 -07:00
|
|
|
setting_inverse_alias :indexable, :noindex
|
2023-08-22 10:02:02 -07:00
|
|
|
setting_inverse_alias :show_followers_count, :hide_followers_count
|
2023-08-14 09:52:45 -07:00
|
|
|
|
2023-03-30 05:44:00 -07:00
|
|
|
namespace :web do
|
|
|
|
setting :advanced_layout, default: false
|
|
|
|
setting :trends, default: true
|
|
|
|
setting :use_blurhash, default: true
|
|
|
|
setting :use_pending_items, default: false
|
|
|
|
setting :use_system_font, default: false
|
|
|
|
setting :disable_swiping, default: false
|
|
|
|
setting :delete_modal, default: true
|
|
|
|
setting :reblog_modal, default: false
|
|
|
|
setting :unfollow_modal, default: true
|
2023-03-31 12:37:57 -07:00
|
|
|
setting :favourite_modal, default: false
|
2023-03-30 05:44:00 -07:00
|
|
|
setting :reduce_motion, default: false
|
|
|
|
setting :expand_content_warnings, default: false
|
|
|
|
setting :display_media, default: 'default', in: %w(default show_all hide_all)
|
|
|
|
setting :auto_play, default: false
|
2023-03-31 12:37:57 -07:00
|
|
|
setting :use_system_emoji_font, default: false
|
2023-03-30 05:44:00 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
namespace :notification_emails do
|
|
|
|
setting :follow, default: true
|
|
|
|
setting :reblog, default: false
|
|
|
|
setting :favourite, default: false
|
|
|
|
setting :mention, default: true
|
|
|
|
setting :follow_request, default: true
|
|
|
|
setting :report, default: true
|
|
|
|
setting :pending_account, default: true
|
|
|
|
setting :trends, default: true
|
2023-03-31 12:37:57 -07:00
|
|
|
setting :link_trends, default: false
|
|
|
|
setting :status_trends, default: false
|
2023-03-30 05:44:00 -07:00
|
|
|
setting :appeal, default: true
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :interactions do
|
|
|
|
setting :must_be_follower, default: false
|
|
|
|
setting :must_be_following, default: false
|
|
|
|
setting :must_be_following_dm, default: false
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(original_hash)
|
|
|
|
@original_hash = original_hash || {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](key)
|
2023-08-14 09:52:45 -07:00
|
|
|
definition = self.class.definition_for(key)
|
2023-03-30 05:44:00 -07:00
|
|
|
|
2023-08-14 09:52:45 -07:00
|
|
|
raise KeyError, "Undefined setting: #{key}" if definition.nil?
|
2023-03-30 05:44:00 -07:00
|
|
|
|
2023-08-14 09:52:45 -07:00
|
|
|
definition.value_for(key, @original_hash[definition.key])
|
2023-03-30 05:44:00 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def []=(key, value)
|
2023-08-14 09:52:45 -07:00
|
|
|
definition = self.class.definition_for(key)
|
2023-03-30 05:44:00 -07:00
|
|
|
|
2023-08-14 09:52:45 -07:00
|
|
|
raise KeyError, "Undefined setting: #{key}" if definition.nil?
|
2023-03-30 05:44:00 -07:00
|
|
|
|
2023-08-14 09:52:45 -07:00
|
|
|
typecast_value = definition.type_cast(value)
|
2023-06-19 06:06:06 -07:00
|
|
|
|
2023-08-14 09:52:45 -07:00
|
|
|
raise ArgumentError, "Invalid value for setting #{definition.key}: #{typecast_value}" if definition.in.present? && definition.in.exclude?(typecast_value)
|
2023-03-30 05:44:00 -07:00
|
|
|
|
|
|
|
if typecast_value.nil?
|
2023-08-14 09:52:45 -07:00
|
|
|
@original_hash.delete(definition.key)
|
2023-03-30 05:44:00 -07:00
|
|
|
else
|
2023-08-14 09:52:45 -07:00
|
|
|
@original_hash[definition.key] = definition.value_for(key, typecast_value)
|
2023-03-30 05:44:00 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(params)
|
|
|
|
params.each do |k, v|
|
|
|
|
self[k] = v unless v.nil?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
keys.each do |key|
|
|
|
|
define_method(key) do
|
|
|
|
self[key]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_json
|
|
|
|
@original_hash
|
|
|
|
end
|
|
|
|
end
|