mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-21 14:23:04 +00:00
Migrate glitch-soc's exclusive user settings
This commit is contained in:
parent
01d6f7529f
commit
3dcba94e68
|
@ -21,18 +21,8 @@ class Settings::FlavoursController < Settings::BaseController
|
|||
end
|
||||
|
||||
def update
|
||||
user_settings.update(user_settings_params)
|
||||
current_user.settings.update(flavour: params.require(:flavour), skin: params.dig(:user, :setting_skin))
|
||||
current_user.save
|
||||
redirect_to action: 'show', flavour: params[:flavour]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_settings
|
||||
UserSettingsDecorator.new(current_user)
|
||||
end
|
||||
|
||||
def user_settings_params
|
||||
{ setting_flavour: params.require(:flavour),
|
||||
setting_skin: params.dig(:user, :setting_skin) }.with_indifferent_access
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ module AccountsHelper
|
|||
end
|
||||
|
||||
def hide_followers_count?(account)
|
||||
Setting.hide_followers_count || account.user&.setting_hide_followers_count
|
||||
Setting.hide_followers_count || account.user&.settings['hide_followers_count']
|
||||
end
|
||||
|
||||
def account_description(account)
|
||||
|
|
|
@ -39,6 +39,10 @@ module HasUserSettings
|
|||
settings['web.delete_modal']
|
||||
end
|
||||
|
||||
def setting_favourite_modal
|
||||
settings['web.favourite_modal']
|
||||
end
|
||||
|
||||
def setting_reduce_motion
|
||||
settings['web.reduce_motion']
|
||||
end
|
||||
|
@ -47,12 +51,20 @@ module HasUserSettings
|
|||
settings['web.use_system_font']
|
||||
end
|
||||
|
||||
def setting_system_emoji_font
|
||||
settings['web.use_system_emoji_font']
|
||||
end
|
||||
|
||||
def setting_noindex
|
||||
settings['noindex']
|
||||
end
|
||||
|
||||
def setting_theme
|
||||
settings['theme']
|
||||
def setting_flavour
|
||||
settings['flavour']
|
||||
end
|
||||
|
||||
def setting_skin
|
||||
settings['skin']
|
||||
end
|
||||
|
||||
def setting_display_media
|
||||
|
@ -107,6 +119,14 @@ module HasUserSettings
|
|||
settings['default_privacy'] || (account.locked? ? 'private' : 'public')
|
||||
end
|
||||
|
||||
def setting_default_content_type
|
||||
settings['default_content_type']
|
||||
end
|
||||
|
||||
def setting_hide_followers_count
|
||||
settings['hide_followers_count']
|
||||
end
|
||||
|
||||
def allows_report_emails?
|
||||
settings['notification_emails.report']
|
||||
end
|
||||
|
@ -123,6 +143,18 @@ module HasUserSettings
|
|||
settings['notification_emails.trends']
|
||||
end
|
||||
|
||||
def allows_trending_tags_review_emails?
|
||||
settings['notification_emails.trends']
|
||||
end
|
||||
|
||||
def allows_trending_links_review_emails?
|
||||
settings['notification_emails.link_trends']
|
||||
end
|
||||
|
||||
def allows_trending_statuses_review_emails?
|
||||
settings['notification_emails.status_trends']
|
||||
end
|
||||
|
||||
def aggregates_reblogs?
|
||||
settings['aggregate_reblogs']
|
||||
end
|
||||
|
|
|
@ -9,12 +9,15 @@ class UserSettings
|
|||
|
||||
setting :always_send_emails, default: false
|
||||
setting :aggregate_reblogs, default: true
|
||||
setting :theme, default: -> { ::Setting.theme }
|
||||
setting :flavour, default: -> { ::Setting.flavour }
|
||||
setting :skin, default: -> { ::Setting.skin }
|
||||
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
|
||||
setting :default_content_type, default: 'text/plain'
|
||||
setting :hide_followers_count, default: false
|
||||
|
||||
namespace :web do
|
||||
setting :crop_images, default: true
|
||||
|
@ -27,10 +30,12 @@ class UserSettings
|
|||
setting :delete_modal, default: true
|
||||
setting :reblog_modal, default: false
|
||||
setting :unfollow_modal, default: true
|
||||
setting :favourite_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
|
||||
setting :use_system_emoji_font, default: false
|
||||
end
|
||||
|
||||
namespace :notification_emails do
|
||||
|
@ -42,6 +47,8 @@ class UserSettings
|
|||
setting :report, default: true
|
||||
setting :pending_account, default: true
|
||||
setting :trends, default: true
|
||||
setting :link_trends, default: false
|
||||
setting :status_trends, default: false
|
||||
setting :appeal, default: true
|
||||
end
|
||||
|
||||
|
|
57
db/migrate/20230215074424_move_glitch_user_settings.rb
Normal file
57
db/migrate/20230215074424_move_glitch_user_settings.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MoveGlitchUserSettings < ActiveRecord::Migration[6.1]
|
||||
class User < ApplicationRecord; end
|
||||
|
||||
MAPPING = {
|
||||
favourite_modal: 'web.favourite_modal',
|
||||
system_emoji_font: 'web.use_system_emoji_font',
|
||||
hide_followers_count: 'hide_followers_count',
|
||||
default_content_type: 'default_content_type',
|
||||
flavour: 'flavour',
|
||||
skin: 'skin',
|
||||
notification_emails: {
|
||||
trending_link: 'notification_emails.link_trends',
|
||||
trending_status: 'notification_emails.status_trends',
|
||||
}.freeze,
|
||||
}.freeze
|
||||
|
||||
class LegacySetting < ApplicationRecord
|
||||
self.table_name = 'settings'
|
||||
|
||||
def var
|
||||
self[:var]&.to_sym
|
||||
end
|
||||
|
||||
def value
|
||||
YAML.safe_load(self[:value], permitted_classes: [ActiveSupport::HashWithIndifferentAccess]) if self[:value].present?
|
||||
end
|
||||
end
|
||||
|
||||
def up
|
||||
User.find_each do |user|
|
||||
previous_settings = LegacySetting.where(thing_type: 'User', thing_id: user.id).index_by(&:var)
|
||||
|
||||
user_settings = Oj.load(user.settings || '{}')
|
||||
user_settings.delete('theme')
|
||||
|
||||
MAPPING.each do |legacy_key, new_key|
|
||||
value = previous_settings[legacy_key]&.value
|
||||
|
||||
next if value.blank?
|
||||
|
||||
if value.is_a?(Hash)
|
||||
value.each do |nested_key, nested_value|
|
||||
user_settings[MAPPING[legacy_key][nested_key.to_sym]] = nested_value
|
||||
end
|
||||
else
|
||||
user_settings[new_key] = value
|
||||
end
|
||||
end
|
||||
|
||||
user.update_column('settings', Oj.dump(user_settings)) # rubocop:disable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2023_02_15_074423) do
|
||||
ActiveRecord::Schema.define(version: 2023_02_15_074424) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
|
Loading…
Reference in a new issue