mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 06:24:48 +08:00
Previously, chat notification settings lived on a separate Chat preferences tab and push delivery was gated by a standalone `only_chat_push_notifications` toggle, splitting notification controls across two places. This change moves the chat notification settings onto the main notifications preferences page and replaces the boolean with a `push_notification_level` dropdown (`none`/`all`/`chat_only`), so push notifications are managed in one place. This follows an established pattern, as the solved and assign plugins do this too. This should make this control more coherent and less confusing. <img width="574" height="838" alt="CleanShot 2026-07-13 at 15 04 03" src="https://github.com/user-attachments/assets/0217cb63-77a3-437a-83ae-8003082af6b7" /> --------- Co-authored-by: Martin Brennan <martin@discourse.org>
36 lines
1 KiB
Ruby
Vendored
36 lines
1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class BackfillPushNotificationLevel < ActiveRecord::Migration[8.0]
|
|
disable_ddl_transaction!
|
|
|
|
# push_notification_level enum: none: 0, all: 1, chat_only: 2
|
|
BATCH_SIZE = 30_000
|
|
|
|
def up
|
|
# `only_chat_push_notifications` is a chat-plugin column; skip when it isn't
|
|
# present (e.g. the chat plugin is absent, or the migrations-tooling core-only
|
|
# schema) so this core migration never references a missing column.
|
|
return unless column_exists?(:user_options, :only_chat_push_notifications)
|
|
|
|
loop do
|
|
count = DB.exec(<<~SQL, batch_size: BATCH_SIZE)
|
|
WITH cte AS (
|
|
SELECT user_id
|
|
FROM user_options
|
|
WHERE only_chat_push_notifications = true AND push_notification_level <> 2
|
|
LIMIT :batch_size
|
|
)
|
|
UPDATE user_options
|
|
SET push_notification_level = 2
|
|
FROM cte
|
|
WHERE user_options.user_id = cte.user_id
|
|
SQL
|
|
|
|
break if count == 0
|
|
end
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|