mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-26 23:41:52 +00:00
ad52b04a1c
Some checks failed
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.1) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.1) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.1) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Crowdin / Upload translations / upload-translations (push) Has been cancelled
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
100 lines
2.8 KiB
Ruby
100 lines
2.8 KiB
Ruby
# 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
|
|
setting :theme, default: -> { ::Setting.theme }
|
|
setting :noindex, default: -> { ::Setting.noindex }
|
|
setting :show_application, default: true
|
|
setting :default_language, default: nil
|
|
setting :default_sensitive, default: false
|
|
setting :default_privacy, default: nil, in: %w(public unlisted private)
|
|
|
|
setting_inverse_alias :indexable, :noindex
|
|
|
|
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 :disable_hover_cards, default: false
|
|
setting :delete_modal, default: true
|
|
setting :reblog_modal, default: false
|
|
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
|
|
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
|
|
setting :appeal, default: true
|
|
setting :software_updates, default: 'critical', in: %w(none critical patch all)
|
|
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)
|
|
definition = self.class.definition_for(key)
|
|
|
|
raise KeyError, "Undefined setting: #{key}" if definition.nil?
|
|
|
|
definition.value_for(key, @original_hash[definition.key])
|
|
end
|
|
|
|
def []=(key, value)
|
|
definition = self.class.definition_for(key)
|
|
|
|
raise KeyError, "Undefined setting: #{key}" if definition.nil?
|
|
|
|
typecast_value = definition.type_cast(value)
|
|
|
|
raise ArgumentError, "Invalid value for setting #{definition.key}: #{typecast_value}" if definition.in.present? && definition.in.exclude?(typecast_value)
|
|
|
|
if typecast_value.nil?
|
|
@original_hash.delete(definition.key)
|
|
else
|
|
@original_hash[definition.key] = definition.value_for(key, typecast_value)
|
|
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
|