mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-25 19:01:37 +01:00
Migrate emoji reactions
This commit is contained in:
parent
68101baae1
commit
e4c411ef1a
6 changed files with 73 additions and 10 deletions
|
@ -127,6 +127,10 @@ module HasUserSettings
|
|||
settings['hide_followers_count']
|
||||
end
|
||||
|
||||
def setting_visible_reactions
|
||||
integer_cast_setting('visible_reactions', 0)
|
||||
end
|
||||
|
||||
def allows_report_emails?
|
||||
settings['notification_emails.report']
|
||||
end
|
||||
|
@ -170,4 +174,14 @@ module HasUserSettings
|
|||
def hide_all_media?
|
||||
settings['web.display_media'] == 'hide_all'
|
||||
end
|
||||
|
||||
def integer_cast_setting(key, min = nil, max = nil)
|
||||
i = ActiveModel::Type::Integer.new.cast(settings[key])
|
||||
# the cast above doesn't return a number if passed the string "e"
|
||||
i = 0 unless i.is_a? Numeric
|
||||
return min if !min.nil? && i < min
|
||||
return max if !max.nil? && i > max
|
||||
|
||||
i
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,6 +18,7 @@ class UserSettings
|
|||
setting :default_privacy, default: nil
|
||||
setting :default_content_type, default: 'text/plain'
|
||||
setting :hide_followers_count, default: false
|
||||
setting :visible_reactions, default: 6
|
||||
|
||||
namespace :web do
|
||||
setting :crop_images, default: true
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
= ff.input :'web.crop_images', wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_crop_images')
|
||||
|
||||
.fields-group.fields-row__column.fields-row__column-6
|
||||
= f.input :setting_visible_reactions, wrapper: :with_label, input_html: { type: 'number', min: '0', data: { default: '6' } }, hint: false
|
||||
= ff.input :'visible_reactions', wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_visible_reactions'), input_html: { type: 'number', min: '0', data: { default: '6' } }, hint: false
|
||||
|
||||
%h4= t 'appearance.discovery'
|
||||
|
||||
|
@ -55,16 +55,16 @@
|
|||
= ff.input :'web.favourite_modal', wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_favourite_modal'), glitch_only: true
|
||||
= ff.input :'web.delete_modal', wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_delete_modal')
|
||||
|
||||
%h4= t 'appearance.sensitive_content'
|
||||
%h4= t 'appearance.sensitive_content'
|
||||
|
||||
.fields-group
|
||||
= ff.input :'web.display_media', collection: ['default', 'show_all', 'hide_all'],label_method: lambda { |item| t("simple_form.hints.defaults.setting_display_media_#{item}") }, hint: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label, label: I18n.t('simple_form.labels.defaults.setting_display_media')
|
||||
.fields-group
|
||||
= f.input :setting_display_media, collection: ['default', 'show_all', 'hide_all'], label_method: lambda { |item| t("simple_form.hints.defaults.setting_display_media_#{item}") }, hint: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label
|
||||
|
||||
.fields-group
|
||||
= ff.input :'web.use_blurhash', wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_use_blurhash'), hint: I18n.t('simple_form.hints.defaults.setting_use_blurhash')
|
||||
.fields-group
|
||||
= f.input :setting_use_blurhash, as: :boolean, wrapper: :with_label
|
||||
|
||||
.fields-group
|
||||
= ff.input :'web.expand_content_warnings', wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_expand_spoilers')
|
||||
.fields-group
|
||||
= f.input :setting_expand_spoilers, as: :boolean, wrapper: :with_label
|
||||
|
||||
.actions
|
||||
= f.button :button, t('generic.save_changes'), type: :submit
|
||||
|
|
48
db/migrate/20230215074425_move_emoji_reaction_settings.rb
Normal file
48
db/migrate/20230215074425_move_emoji_reaction_settings.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MoveEmojiReactionSettings < ActiveRecord::Migration[6.1]
|
||||
class User < ApplicationRecord; end
|
||||
|
||||
MAPPING = {
|
||||
setting_visible_reactions: 'visible_reactions',
|
||||
}.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_074424) do
|
||||
ActiveRecord::Schema.define(version: 2023_02_15_074425) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
|
|
@ -25,7 +25,7 @@ module Mastodon
|
|||
end
|
||||
|
||||
def suffix_version
|
||||
'+1.0.2'
|
||||
'+1.0.3'
|
||||
end
|
||||
|
||||
def to_a
|
||||
|
|
Loading…
Reference in a new issue