From 1d69aef2dbd91252e96fb093c92e9ec75695e2ca Mon Sep 17 00:00:00 2001 From: KMY Date: Sun, 22 Oct 2023 11:06:17 +0900 Subject: [PATCH 1/6] Bump version to 8.0 --- lib/mastodon/version.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index 0f33cb70cb867e..8d999a1cd700b0 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -5,11 +5,11 @@ module Version module_function def kmyblue_major - 7 + 8 end def kmyblue_minor - 2 + 0 end def kmyblue_flag From 759b2a203930c9ad6354eb7664da509092e6d410 Mon Sep 17 00:00:00 2001 From: KMY Date: Sun, 22 Oct 2023 12:14:53 +0900 Subject: [PATCH 2/6] =?UTF-8?q?Add:=20=E4=BB=96=E3=81=AE=E3=82=B5=E3=83=BC?= =?UTF-8?q?=E3=83=90=E3=83=BC=E3=81=AB=E5=85=AC=E9=96=8B=E3=81=99=E3=82=8B?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=81=AB=E3=80=81=E5=88=B6=E9=99=90=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E3=81=AA=E3=81=A9=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/kmyblue_capabilities_helper.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/helpers/kmyblue_capabilities_helper.rb b/app/helpers/kmyblue_capabilities_helper.rb index 455561a597f029..07f22e8db5a958 100644 --- a/app/helpers/kmyblue_capabilities_helper.rb +++ b/app/helpers/kmyblue_capabilities_helper.rb @@ -37,6 +37,10 @@ def capabilities_for_nodeinfo status_reference quote kmyblue_quote + kmyblue_subscribable + kmyblue_translation + kmyblue_link_preview + kmyblue_emoji_reaction_policy searchability kmyblue_searchability visibility_mutual @@ -45,6 +49,8 @@ def capabilities_for_nodeinfo kmyblue_bookmark_category kmyblue_searchability_limited kmyblue_circle_history + kmyblue_emoji_license + emoji_keywords ) capabilities << :full_text_search if Chewy.enabled? From 10fec60f1ab37bce5caa697ad0dbbe625f7a9a56 Mon Sep 17 00:00:00 2001 From: KMY Date: Sun, 22 Oct 2023 17:27:17 +0900 Subject: [PATCH 3/6] =?UTF-8?q?Fix:=20`quote=5Fof=5Fid`=E3=81=AE=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=83=87=E3=83=83=E3=82=AF=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20231022074913_add_statuses_quote_index.rb | 13 +++++++++++++ db/schema.rb | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/post_migrate/20231022074913_add_statuses_quote_index.rb diff --git a/db/post_migrate/20231022074913_add_statuses_quote_index.rb b/db/post_migrate/20231022074913_add_statuses_quote_index.rb new file mode 100644 index 00000000000000..98025700fcb40e --- /dev/null +++ b/db/post_migrate/20231022074913_add_statuses_quote_index.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require Rails.root.join('lib', 'mastodon', 'migration_helpers') + +class AddStatusesQuoteIndex < ActiveRecord::Migration[7.0] + include Mastodon::MigrationHelpers + + disable_ddl_transaction! + + def change + safety_assured { add_index :statuses, [:quote_of_id, :account_id], unique: false } + end +end diff --git a/db/schema.rb b/db/schema.rb index af31ed869b33a9..071f29c2e0d91c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_21_005339) do +ActiveRecord::Schema[7.0].define(version: 2023_10_22_074913) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1228,6 +1228,7 @@ t.index ["id", "account_id"], name: "index_statuses_public_20200119", order: { id: :desc }, where: "((deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))" t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id", where: "(in_reply_to_account_id IS NOT NULL)" t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id", where: "(in_reply_to_id IS NOT NULL)" + t.index ["quote_of_id", "account_id"], name: "index_statuses_on_quote_of_id_and_account_id" t.index ["reblog_of_id", "account_id"], name: "index_statuses_on_reblog_of_id_and_account_id" t.index ["uri"], name: "index_statuses_on_uri", unique: true, opclass: :text_pattern_ops, where: "(uri IS NOT NULL)" end From 3ce7537a836a1d98729dac950c4ba8628eddd067 Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 23 Oct 2023 09:11:45 +0900 Subject: [PATCH 4/6] =?UTF-8?q?Fix:=20#172=20=E4=BB=96=E3=81=AE=E3=82=B5?= =?UTF-8?q?=E3=83=BC=E3=83=90=E3=83=BC=E3=81=8B=E3=82=89=E3=81=AE=E7=9B=B8?= =?UTF-8?q?=E4=B9=97=E3=82=8A=E7=B5=B5=E6=96=87=E5=AD=97=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=8C=E5=8F=8D=E6=98=A0=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/activitypub/activity/undo.rb | 7 ++- spec/lib/activitypub/activity/undo_spec.rb | 60 ++++++++++++++++++++-- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/app/lib/activitypub/activity/undo.rb b/app/lib/activitypub/activity/undo.rb index eac34efdc9697b..f99d949c39e897 100644 --- a/app/lib/activitypub/activity/undo.rb +++ b/app/lib/activitypub/activity/undo.rb @@ -135,7 +135,12 @@ def undo_like if shortcode.present? emoji_tag = @object['tag'].is_a?(Array) ? @object['tag']&.first : @object['tag'] - emoji = CustomEmoji.find_by(shortcode: shortcode, domain: @account.domain) if emoji_tag.present? && emoji_tag['id'].present? + emoji = nil + if emoji_tag.present? && emoji_tag['id'].present? + domain = URI.split(emoji_tag['id'])[2] + domain = nil if domain == Rails.configuration.x.local_domain || domain == Rails.configuration.x.web_domain + emoji = CustomEmoji.find_by(shortcode: shortcode, domain: domain) if emoji_tag.present? && emoji_tag['id'].present? + end emoji_reaction = @original_status.emoji_reactions.where(account: @account, name: shortcode, custom_emoji: emoji).first diff --git a/spec/lib/activitypub/activity/undo_spec.rb b/spec/lib/activitypub/activity/undo_spec.rb index feda725654679f..cd12c5bd0cae82 100644 --- a/spec/lib/activitypub/activity/undo_spec.rb +++ b/spec/lib/activitypub/activity/undo_spec.rb @@ -5,7 +5,8 @@ RSpec.describe ActivityPub::Activity::Undo do subject { described_class.new(json, sender) } - let(:sender) { Fabricate(:account, domain: 'example.com') } + let(:sender_domain) { 'example.com' } + let(:sender) { Fabricate(:account, domain: sender_domain) } let(:json) do { @@ -218,6 +219,8 @@ let(:status) { Fabricate(:status) } let(:content) { '😀' } + let(:name) { '😀' } + let(:tag) { nil } let(:object_json) do { id: 'bar', @@ -225,20 +228,69 @@ actor: ActivityPub::TagManager.instance.uri_for(sender), object: ActivityPub::TagManager.instance.uri_for(status), content: content, + tag: tag, } end + let(:custom_emoji) { nil } before do Fabricate(:favourite, account: sender, status: status) - Fabricate(:emoji_reaction, account: sender, status: status, name: content) + Fabricate(:emoji_reaction, account: sender, status: status, name: name, custom_emoji: custom_emoji) end it 'delete emoji reaction' do subject.perform - reaction = EmojiReaction.find_by(account: sender, status: status) - expect(reaction).to be_nil + expect(sender.emoji_reacted?(status)).to be false expect(sender.favourited?(status)).to be true end + + context 'with custom emoji' do + let(:content) { ':tinking:' } + let(:name) { 'tinking' } + let(:tag) do + { + id: custom_emoji_uri, + type: 'Emoji', + icon: { + url: 'http://example.com/emoji.png', + }, + name: name, + } + end + let(:custom_emoji_domain) { 'example.com' } + let(:custom_emoji_uri) { "https://#{custom_emoji_domain}/aaa" } + let(:custom_emoji) { Fabricate(:custom_emoji, uri: custom_emoji_uri, domain: custom_emoji_domain, shortcode: name) } + + it 'delete emoji reaction' do + subject.perform + expect(sender.emoji_reacted?(status)).to be false + expect(sender.favourited?(status)).to be true + end + + context 'when third server' do + let(:sender_domain) { 'foo.bar' } + + it 'delete emoji reaction' do + subject.perform + expect(sender.emoji_reacted?(status)).to be false + expect(sender.favourited?(status)).to be true + end + end + + context 'when local' do + let(:custom_emoji_domain) { 'cb6e6126.ngrok.io' } + + before do + custom_emoji.update(domain: nil, uri: nil) + end + + it 'delete emoji reaction' do + subject.perform + expect(sender.emoji_reacted?(status)).to be false + expect(sender.favourited?(status)).to be true + end + end + end end end end From 121843461d4be856aff3037ecfca1d73d1069474 Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 23 Oct 2023 10:07:17 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Test:=20#166=20=E3=83=AA=E3=83=A2=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=81=8B=E3=82=89=E8=87=AA=E5=88=86=E3=81=AE=E7=B5=B5?= =?UTF-8?q?=E6=96=87=E5=AD=97=E3=82=92=E5=8F=97=E3=81=91=E5=8F=96=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E6=99=82=E3=80=81=E3=83=A9=E3=82=A4=E3=82=BB=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=81=8C=E4=B8=8A=E6=9B=B8=E3=81=8D=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=93=E3=81=A8=E3=82=92=E7=A2=BA=E8=AA=8D?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/lib/activitypub/activity/like_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/lib/activitypub/activity/like_spec.rb b/spec/lib/activitypub/activity/like_spec.rb index 16ea81dccdf436..25037ed6355392 100644 --- a/spec/lib/activitypub/activity/like_spec.rb +++ b/spec/lib/activitypub/activity/like_spec.rb @@ -182,6 +182,7 @@ url: 'http://example.com/emoji.png', }, name: 'tinking', + license: 'Ohagi but everyone', } end @@ -198,6 +199,11 @@ expect(subject.first.custom_emoji.domain).to be_nil expect(sender.favourited?(status)).to be false end + + it 'not change license' do + expect(subject.first.custom_emoji.reload.license).to eq 'Everyone but Ohagi' + expect(subject.first.custom_emoji.reload.uri).to be_nil + end end context 'with unicode emoji and reject_media enabled' do From 3b9258553676716188f9068a3e36b598ac7a9df9 Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 23 Oct 2023 18:28:38 +0900 Subject: [PATCH 6/6] =?UTF-8?q?Change:=20#70=20DTL=E6=8A=95=E7=A8=BF?= =?UTF-8?q?=E3=81=A7=E3=80=81=E5=85=AC=E9=96=8B=E7=AF=84=E5=9B=B2=E3=83=BB?= =?UTF-8?q?=E6=A4=9C=E7=B4=A2=E8=A8=B1=E5=8F=AF=E3=82=92=E5=88=A5=E3=80=85?= =?UTF-8?q?=E3=81=AB=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/has_user_settings.rb | 8 ++- app/models/user_settings.rb | 3 +- app/services/post_status_service.rb | 4 +- .../settings/preferences/other/show.html.haml | 5 +- config/locales/simple_form.en.yml | 19 ++++--- config/locales/simple_form.ja.yml | 19 ++++--- ...231023083359_convert_dtl_force_settings.rb | 52 +++++++++++++++++++ db/schema.rb | 2 +- 8 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 db/migrate/20231023083359_convert_dtl_force_settings.rb diff --git a/app/models/concerns/has_user_settings.rb b/app/models/concerns/has_user_settings.rb index 820c41360d4efc..e264edb3b5bda1 100644 --- a/app/models/concerns/has_user_settings.rb +++ b/app/models/concerns/has_user_settings.rb @@ -143,8 +143,12 @@ def setting_link_preview settings['link_preview'] end - def setting_dtl_force_with_tag - settings['dtl_force_with_tag']&.to_sym || :none + def setting_dtl_force_visibility + settings['dtl_force_visibility']&.to_sym || :unchange + end + + def setting_dtl_force_searchability + settings['dtl_force_searchability']&.to_sym || :unchange end def setting_dtl_force_subscribable diff --git a/app/models/user_settings.rb b/app/models/user_settings.rb index e353ec7b2a7d53..6c25b61367e2fb 100644 --- a/app/models/user_settings.rb +++ b/app/models/user_settings.rb @@ -38,7 +38,8 @@ class KeyError < Error; end setting :emoji_reaction_streaming_notify_impl2, default: false setting :emoji_reaction_policy, default: :allow, in: %w(allow outside_only followers_only following_only mutuals_only block) setting :unsafe_limited_distribution, default: false - setting :dtl_force_with_tag, default: :none, in: %w(full searchability none) + setting :dtl_force_visibility, default: :unchange, in: %w(unchange public public_unlisted unlisted) + setting :dtl_force_searchability, default: :unchange, in: %w(unchange public public_unlisted) setting :dtl_force_subscribable, default: false setting :lock_follow_from_bot, default: false setting :allow_quote, default: true diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index 0e3bd8805de509..57ca1b940fc92c 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -111,8 +111,8 @@ def overwrite_dtl_post return if raw_tags.exclude?(DTL_TAG) return unless %i(public public_unlisted unlisted).include?(@visibility) - @visibility = :unlisted if @account.user&.setting_dtl_force_with_tag == :full - @searchability = :public if %i(full searchability).include?(@account.user&.setting_dtl_force_with_tag) + @visibility = @account.user&.setting_dtl_force_visibility if %i(public public_unlisted unlisted).include?(@account.user&.setting_dtl_force_visibility) + @searchability = @account.user&.setting_dtl_force_searchability if %i(public public_unlisted).include?(@account.user&.setting_dtl_force_searchability) @dtl = true end diff --git a/app/views/settings/preferences/other/show.html.haml b/app/views/settings/preferences/other/show.html.haml index 353715df01a66e..68ea7c8ffc39b7 100644 --- a/app/views/settings/preferences/other/show.html.haml +++ b/app/views/settings/preferences/other/show.html.haml @@ -38,7 +38,10 @@ = ff.input :'web.enable_dtl_menu', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_dtl_menu') .fields-group - = ff.input :dtl_force_with_tag, kmyblue: true, collection: ['full', 'searchability', 'none'], label_method: lambda { |item| safe_join([t("simple_form.labels.dtl_force_with_tag.#{item}")]) }, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label, label: I18n.t('simple_form.labels.defaults.setting_dtl_force_with_tag'), hint: I18n.t('simple_form.hints.defaults.setting_dtl_force_with_tag', tag: @dtl_tag) + = ff.input :dtl_force_visibility, kmyblue: true, collection: ['unchange', 'public', 'public_unlisted', 'unlisted'], label_method: lambda { |item| safe_join([t("simple_form.labels.dtl_force_visibility.#{item}")]) }, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label, label: I18n.t('simple_form.labels.defaults.setting_dtl_force_visibility'), hint: I18n.t('simple_form.hints.defaults.setting_dtl_force_visibility', tag: @dtl_tag) + + .fields-group + = ff.input :dtl_force_searchability, kmyblue: true, collection: ['unchange', 'public', 'public_unlisted'], label_method: lambda { |item| safe_join([t("simple_form.labels.dtl_force_searchability.#{item}")]) }, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label, label: I18n.t('simple_form.labels.defaults.setting_dtl_force_searchability'), hint: I18n.t('simple_form.hints.defaults.setting_dtl_force_searchability', tag: @dtl_tag) .fields-group = ff.input :dtl_force_subscribable, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_dtl_force_subscribable'), hint: I18n.t('simple_form.hints.defaults.setting_dtl_force_subscribable') diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 2b777aaa2b00c7..0c7ff8b3cd8c67 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -68,7 +68,8 @@ en: setting_display_media_hide_all: Always hide media setting_display_media_show_all: Always show media setting_dtl_force_subscribable: Your post can be detected local user's antenna to subscribe deep timeline - setting_dtl_force_with_tag: "With using #%{tag} tag, your post settings will be changed forcibly" + setting_dtl_force_searchability: "With using #%{tag} tag, your post settings will be changed forcibly" + setting_dtl_force_visibility: "With using #%{tag} tag, your post settings will be changed forcibly" setting_dtl_menu: Show DTL menu on web setting_emoji_reaction_policy: Even with this setting, users on other servers are free to put their stamp on the post and share it within the same server. If you simply want to remove the stamp from your own screen, you can disable it from the appearance settings setting_enable_emoji_reaction: If turn off, other users still can react your posts @@ -248,7 +249,8 @@ en: setting_display_media_hide_all: Hide all setting_display_media_show_all: Show all setting_dtl_force_subscribable: Ignore your dissubscribable setting when using the DTL tag - setting_dtl_force_with_tag: Post with DTL tag + setting_dtl_force_searchability: Post searchability + setting_dtl_force_visibility: Post visibility setting_emoji_reaction_streaming_notify_impl2: Enable stamp notification compat with Nyastodon, Catstodon, glitch-soc setting_enable_emoji_reaction: Use stamp function setting_enable_login_privacy: Enable login visibility @@ -299,10 +301,15 @@ en: username: Username username_or_email: Username or Email whole_word: Whole word - dtl_force_with_tag: - full: Visibility is unlisted, searchability is everyone - none: No changes - searchability: Searchability is everyone + dtl_force_searchability: + public: Everyone + public_unlisted: Local and followers + unchange: Unchange + dtl_force_visibility: + public: Public + public_unlisted: Public unlisted + unchange: Unchange + unlisted: Unlisted email_domain_block: with_dns_records: Include MX records and IPs of the domain emoji_reactions: diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index e474b47cbc8833..a38b698d452d15 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -74,7 +74,8 @@ ja: setting_display_media_hide_all: メディアを常に隠す setting_display_media_show_all: メディアを常に表示する setting_dtl_force_subscribable: 購読拒否設定に関係なく、ディープタイムラインに向けた投稿はアンテナに掲載されます。ディープタイムラインをアンテナ経由で閲覧している人にあなたの発言が届きます - setting_dtl_force_with_tag: "ハッシュタグ #%{tag} をつけて投稿するとき、公開範囲と検索許可を強制的に置き換えるかを設定します" + setting_dtl_force_searchability: "ハッシュタグ #%{tag} をつけて投稿するとき、検索許可を強制的に置き換えるかを設定します" + setting_dtl_force_visibility: "ハッシュタグ #%{tag} をつけて投稿するとき、公開範囲を強制的に置き換えるかを設定します" setting_emoji_reaction_policy: この設定をしても他のサーバーのユーザーはその投稿に自由にスタンプをつけ、同じサーバーの中で共有できます。単にあなた自身の画面からスタンプを除去したいだけなら、外観設定からスタンプを無効にすることができます setting_emoji_reaction_streaming_notify_impl2: 当該サーバーの独自機能に対応したアプリを利用時に、スタンプ機能を利用できます。動作確認していないため(そもそもそのようなアプリ自体を確認できていないため)正しく動かない場合があります setting_enable_emoji_reaction: この機能を無効にしても、他の人はあなたの投稿にスタンプをつけられます @@ -262,7 +263,8 @@ ja: setting_display_media_hide_all: 非表示 setting_display_media_show_all: 表示 setting_dtl_force_subscribable: ディープタイムライン用のハッシュタグを購読するアンテナに限り、購読拒否設定を無視する - setting_dtl_force_with_tag: DTL参加時の投稿設定 + setting_dtl_force_searchability: DTL投稿の検索許可 + setting_dtl_force_visibility: DTL投稿の公開範囲 setting_dtl_menu: Webクライアントのメニューにディープタイムラインを追加する setting_enable_login_privacy: 公開範囲「ログインユーザーのみ」をWeb UIで選択可能にする setting_emoji_reaction_policy: スタンプ受け入れと表示設定 @@ -315,10 +317,15 @@ ja: username: ユーザー名 username_or_email: ユーザー名またはメールアドレス whole_word: 単語全体にマッチ - dtl_force_with_tag: - full: 公開範囲「未収載」検索許可「誰でも」にする - none: 公開範囲も検索許可も変更しない - searchability: 検索許可を「誰でも」にする + dtl_force_searchability: + public: 誰でも + public_unlisted: ローカルとフォロワー + unchange: 変更しない + dtl_force_visibility: + public: 公開 + public_unlisted: ローカル公開 + unchange: 変更しない + unlisted: 非収載 email_domain_block: with_dns_records: ドメインのMXレコードとIPアドレスを含む emoji_reactions: diff --git a/db/migrate/20231023083359_convert_dtl_force_settings.rb b/db/migrate/20231023083359_convert_dtl_force_settings.rb new file mode 100644 index 00000000000000..165b73671e1ba8 --- /dev/null +++ b/db/migrate/20231023083359_convert_dtl_force_settings.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require Rails.root.join('lib', 'mastodon', 'migration_helpers') + +class ConvertDtlForceSettings < ActiveRecord::Migration[7.0] + include Mastodon::MigrationHelpers + + disable_ddl_transaction! + + class User < ApplicationRecord; end + + def up + safety_assured do + User.transaction do + User.find_in_batches do |users| + users.filter { |user| user.settings.present? }.each do |user| + json = Oj.load(user.settings, symbol_keys: true) + dtl_force_with_tag = json.delete(:dtl_force_with_tag) + next if dtl_force_with_tag.blank? + + json[:dtl_force_visibility] = dtl_force_with_tag == 'full' ? 'unlisted' : 'unchange' + json[:dtl_force_searchability] = dtl_force_with_tag == 'none' ? 'unchange' : 'public' + user.update(settings: Oj.dump(json)) + end + end + end + end + end + + def down + safety_assured do + User.transaction do + User.find_in_batches do |users| + users.filter { |user| user.settings.present? }.each do |user| + json = Oj.load(user.settings, symbol_keys: true) + dtl_force_visibility = json.delete(:dtl_force_visibility) + dtl_force_searchability = json.delete(:dtl_force_searchability) + next unless dtl_force_visibility.present? || dtl_force_searchability.present? + + json[:dtl_force_with_tag] = case dtl_force_visibility + when 'unlisted' + 'full' + else + dtl_force_searchability == 'unchange' ? 'none' : 'searchability' + end + user.update(settings: Oj.dump(json)) + end + end + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 071f29c2e0d91c..e43428edf863b7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_22_074913) do +ActiveRecord::Schema[7.0].define(version: 2023_10_23_083359) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"