Skip to content

A platform for community discussion. Free, open, simple.

UX: Consolidate chat notifications into live notification preferences (#41538)

chapoiceed7027deff
diff --git a/app/models/user_option.rb b/app/models/user_option.rb
index 457bdc96871..6796825fb9e 100644
--- a/app/models/user_option.rb
+++ b/app/models/user_option.rb
@@ -19,6 +19,7 @@ class UserOption < ActiveRecord::Base
self.ignored_columns = [
"enable_experimental_sidebar", # TODO: Remove when 20250804021210_drop_enable_experimental_sidebar_user_option has been promoted to pre-deploy
+ "only_chat_push_notifications", # TODO(2027-01): replaced by push_notification_level; drop the column in a follow-up PR once this has shipped
]
self.primary_key = :user_id
@@ -31,6 +32,7 @@ class UserOption < ActiveRecord::Base
scope :human_users, -> { where("user_id > 0") }
enum :default_calendar, { none_selected: 0, ics: 1, google: 2 }, scopes: false
+ enum :push_notification_level, { none: 0, all: 1, chat_only: 2 }, prefix: true, scopes: false
def self.ensure_consistency!
sql = <<~SQL
@@ -316,8 +318,8 @@ end
# notify_on_linked_posts :boolean default(TRUE), not null
# notify_on_solved :boolean default(TRUE), not null
# oldest_search_log_date :datetime
-# only_chat_push_notifications :boolean
# policy_email_frequency :integer default("never"), not null
+# push_notification_level :integer default("all"), not null
# seen_popups :integer is an Array
# show_original_content :boolean default(FALSE), not null
# show_thread_title_prompts :boolean default(TRUE), not null
diff --git a/app/serializers/user_option_serializer.rb b/app/serializers/user_option_serializer.rb
index 9b2c4879270..e6abb362d39 100644
--- a/app/serializers/user_option_serializer.rb
+++ b/app/serializers/user_option_serializer.rb
@@ -24,6 +24,7 @@ class UserOptionSerializer < ApplicationSerializer
:email_in_reply_to,
:like_notification_frequency,
:notify_on_linked_posts,
+ :push_notification_level,
:enable_upcoming_change_available_notifications,
:include_tl0_in_digests,
:theme_ids,
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb
index 2d397a71b52..9bb01c0c3f5 100644
--- a/app/services/user_updater.rb
+++ b/app/services/user_updater.rb
@@ -40,6 +40,7 @@ class UserUpdater
email_in_reply_to
like_notification_frequency
notify_on_linked_posts
+ push_notification_level
enable_upcoming_change_available_notifications
include_tl0_in_digests
theme_ids
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 2d6a7b3432c..26412724403 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1741,6 +1741,11 @@ en:
statistics: "Stats"
desktop_notifications:
label: "Live notifications"
+ push_level:
+ title: "Push notifications are…"
+ none: "Disabled"
+ all: "Enabled"
+ chat_only: "Enabled for chat only"
not_supported: "Notifications are not supported on this browser. Sorry."
perm_default: "Turn on notifications"
perm_denied_btn: "Permission denied"
diff --git a/db/migrate/20260707184146_add_push_notification_level_to_user_options.rb b/db/migrate/20260707184146_add_push_notification_level_to_user_options.rb
new file mode 100644
index 00000000000..d9f4aac9ef7
--- /dev/null
+++ b/db/migrate/20260707184146_add_push_notification_level_to_user_options.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AddPushNotificationLevelToUserOptions < ActiveRecord::Migration[8.0]
+ def change
+ # push_notification_level enum: none: 0, all: 1, chat_only: 2. Default to `all`
+ # to preserve the prior behaviour where push notifications were enabled.
+ add_column :user_options, :push_notification_level, :integer, null: false, default: 1
+ end
+end
diff --git a/db/post_migrate/20260707184150_backfill_push_notification_level.rb b/db/post_migrate/20260707184150_backfill_push_notification_level.rb
new file mode 100644
index 00000000000..cb23db643c2
--- /dev/null
+++ b/db/post_migrate/20260707184150_backfill_push_notification_level.rb
@@ -0,0 +1,36 @@
+# 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
diff --git a/db/structure.sql b/db/structure.sql
index cad051900be..b9cdea601d9 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -11534,7 +11534,8 @@ CREATE TABLE public.user_options (
show_original_content boolean DEFAULT false NOT NULL,
enable_upcoming_change_available_notifications boolean DEFAULT true NOT NULL,
chat_announce_new_messages boolean DEFAULT true NOT NULL,
- chat_new_message_sound boolean DEFAULT false NOT NULL
+ chat_new_message_sound boolean DEFAULT false NOT NULL,
+ push_notification_level integer DEFAULT 1 NOT NULL
);
@@ -22585,6 +22586,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20260713180615'),
('20260708095336'),
('20260708080308'),
+('20260707184150'),
+('20260707184146'),
('20260707013407'),
('20260703164430'),
('20260703163425'),
diff --git a/frontend/discourse/app/components/push-notification-select.gjs b/frontend/discourse/app/components/push-notification-select.gjs
new file mode 100644
index 00000000000..95743d514bf
--- /dev/null
+++ b/frontend/discourse/app/components/push-notification-select.gjs
@@ -0,0 +1,121 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import ComboBox from "discourse/select-kit/components/combo-box";
+import DButton from "discourse/ui-kit/d-button";
+import { i18n } from "discourse-i18n";
+
+export default class PushNotificationSelect extends Component {
+ @service desktopNotifications;
+ @service siteSettings;
+
+ @tracked level;
+
+ constructor() {
+ super(...arguments);
+ this.level = this.args.model.user_option.push_notification_level;
+ }
+
+ get chatAvailable() {
+ return (
+ this.siteSettings.chat_enabled && this.args.model.user_option.chat_enabled
+ );
+ }
+
+ get content() {
+ const options = [
+ {
+ name: i18n("user.desktop_notifications.push_level.none"),
+ value: "none",
+ },
+ { name: i18n("user.desktop_notifications.push_level.all"), value: "all" },
+ ];
+
+ if (this.chatAvailable) {
+ options.push({
+ name: i18n("user.desktop_notifications.push_level.chat_only"),
+ value: "chat_only",
+ });
+ }
+
+ return options;
+ }
+
+ get value() {
+ if (!this.desktopNotifications.isSubscribed) {
+ return "none";
+ }
+
+ if (this.level === "chat_only" && !this.chatAvailable) {
+ return "all";
+ }
+
+ return this.level;
+ }
+
+ @action
+ async onChange(value) {
+ if (value === "none") {
+ await this.desktopNotifications.disable();
+ await this.persistLevel("none");
+ return;
+ }
+
+ if (!this.desktopNotifications.isSubscribed) {
+ try {
+ await this.desktopNotifications.enable();
+ } catch {
+ // handled by the subscription check below
+ }
+
+ if (!this.desktopNotifications.isSubscribed) {
+ this.level = "none";
+ return;
+ }
+ }
+
+ await this.persistLevel(value);
+ }
+
+ async persistLevel(value) {
+ this.level = value;
+ this.args.model.set("user_option.push_notification_level", value);
+ await this.args.model
+ .save(["push_notification_level"])
+ .catch(popupAjaxError);
+ }
+
+ <template>
+ {{#if this.desktopNotifications.isNotSupported}}
+ <DButton
+ @icon="bell-slash"
+ @label="user.desktop_notifications.not_supported"
+ @disabled="true"
+ class="btn-default"
+ />
+ {{else if this.desktopNotifications.isDeniedPermission}}
+ <DButton
+ @icon="bell-slash"
+ @label="user.desktop_notifications.perm_denied_btn"
+ @disabled="true"
+ class="btn-default"
+ />
+ <span>
+ {{i18n "user.desktop_notifications.perm_denied_expl"}}
+ </span>
+ {{else}}
+ <label class="sr-only">{{i18n
+ "user.desktop_notifications.push_level.title"
+ }}</label>
+ <ComboBox
+ @valueProperty="value"
+ @content={{this.content}}
+ @value={{this.value}}
+ @onChange={{this.onChange}}
+ class="push-notification-select"
+ />
+ {{/if}}
+ </template>
+}
diff --git a/frontend/discourse/app/controllers/preferences/notifications.js b/frontend/discourse/app/controllers/preferences/notifications.js
index 358532afd31..7c2d9a4b9fd 100644
--- a/frontend/discourse/app/controllers/preferences/notifications.js
+++ b/frontend/discourse/app/controllers/preferences/notifications.js
@@ -29,6 +29,7 @@ export default class NotificationsController extends Controller {
"new_topic_duration_minutes",
"notification_level_when_replying",
"notify_on_linked_posts",
+ "push_notification_level",
"enable_upcoming_change_available_notifications",
"user_notification_schedule",
],
diff --git a/frontend/discourse/app/models/user.js b/frontend/discourse/app/models/user.js
index d9036c22d98..868c2af160d 100644
--- a/frontend/discourse/app/models/user.js
+++ b/frontend/discourse/app/models/user.js
@@ -140,6 +140,7 @@ let userOptionFields = [
"new_topic_duration_minutes",
"notification_level_when_replying",
"notify_on_linked_posts",
+ "push_notification_level",
"seen_popups",
"show_original_content",
"sidebar_link_to_filtered_list",
diff --git a/frontend/discourse/app/templates/preferences/notifications.gjs b/frontend/discourse/app/templates/preferences/notifications.gjs
index 14c72261e61..20936b6458b 100644
--- a/frontend/discourse/app/templates/preferences/notifications.gjs
+++ b/frontend/discourse/app/templates/preferences/notifications.gjs
@@ -1,7 +1,7 @@
import { fn } from "@ember/helper";
-import DesktopNotificationConfig from "discourse/components/desktop-notification-config";
import PluginOutlet from "discourse/components/plugin-outlet";
import PreferenceCheckbox from "discourse/components/preference-checkbox";
+import PushNotificationSelect from "discourse/components/push-notification-select";
import UserNotificationSchedule from "discourse/components/user-notification-schedule";
import lazyHash from "discourse/helpers/lazy-hash";
import ComboBox from "discourse/select-kit/components/combo-box";
@@ -43,7 +43,7 @@ export default <template>
<label class="control-label">{{i18n
"user.desktop_notifications.label"
}}</label>
- <DesktopNotificationConfig />
+ <PushNotificationSelect @model={{@controller.model}} />
<div class="instructions">{{i18n
"user.desktop_notifications.each_browser_note"
}}</div>
diff --git a/frontend/discourse/tests/integration/components/push-notification-select-test.gjs b/frontend/discourse/tests/integration/components/push-notification-select-test.gjs
new file mode 100644
index 00000000000..5f506ff5298
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/push-notification-select-test.gjs
@@ -0,0 +1,170 @@
+import { tracked } from "@glimmer/tracking";
+import EmberObject from "@ember/object";
+import Service from "@ember/service";
+import { render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import PushNotificationSelect from "discourse/components/push-notification-select";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+
+class StubDesktopNotifications extends Service {
+ @tracked isNotSupported = false;
+ @tracked isDeniedPermission = false;
+ @tracked isSubscribed = false;
+
+ enable() {
+ this.isSubscribed = true;
+ }
+
+ disable() {
+ this.isSubscribed = false;
+ }
+}
+
+module("Integration | Component | push-notification-select", function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.owner.register(
+ "service:desktop-notifications",
+ StubDesktopNotifications
+ );
+ this.desktopNotifications = this.owner.lookup(
+ "service:desktop-notifications"
+ );
+ this.siteSettings.chat_enabled = true;
+ this.model = EmberObject.create({
+ savedFields: null,
+ user_option: EmberObject.create({
+ push_notification_level: "all",
+ chat_enabled: true,
+ }),
+ save(fields) {
+ this.savedFields = fields;
+ return Promise.resolve();
+ },
+ });
+ });
+
+ test("shows 'none' while the device is not subscribed", async function (assert) {
+ await render(
+ <template><PushNotificationSelect @model={{this.model}} /></template>
+ );
+
+ assert.strictEqual(
+ selectKit(".push-notification-select").header().value(),
+ "none"
+ );
+ });
+
+ test("reflects the stored level while subscribed", async function (assert) {
+ this.desktopNotifications.isSubscribed = true;
+ this.model.user_option.set("push_notification_level", "chat_only");
+
+ await render(
+ <template><PushNotificationSelect @model={{this.model}} /></template>
+ );
+
+ assert.strictEqual(
+ selectKit(".push-notification-select").header().value(),
+ "chat_only"
+ );
+ });
+
+ test("hides the chat option when chat is disabled for the user", async function (assert) {
+ this.model.user_option.set("chat_enabled", false);
+
+ await render(
+ <template><PushNotificationSelect @model={{this.model}} /></template>
+ );
+
+ await selectKit(".push-notification-select").expand();
+
+ assert.deepEqual(
+ selectKit(".push-notification-select")
+ .displayedContent()
+ .map((r) => r.id),
+ ["none", "all"]
+ );
+ });
+
+ test("selecting 'Nothing' unsubscribes and stores none", async function (assert) {
+ this.desktopNotifications.isSubscribed = true;
+
+ await render(
+ <template><PushNotificationSelect @model={{this.model}} /></template>
+ );
+
+ await selectKit(".push-notification-select").expand();
+ await selectKit(".push-notification-select").selectRowByValue("none");
+
+ assert.false(this.desktopNotifications.isSubscribed);
+ assert.strictEqual(this.model.user_option.push_notification_level, "none");
+ });
+
+ test("selecting a level subscribes, stores it, and reflects it in the header", async function (assert) {
+ await render(
+ <template><PushNotificationSelect @model={{this.model}} /></template>
+ );
+
+ await selectKit(".push-notification-select").expand();
+ await selectKit(".push-notification-select").selectRowByValue("chat_only");
+
+ assert.true(this.desktopNotifications.isSubscribed);
+ assert.strictEqual(
+ this.model.user_option.push_notification_level,
+ "chat_only"
+ );
+ assert.strictEqual(
+ selectKit(".push-notification-select").header().value(),
+ "chat_only"
+ );
+ });
+
+ test("switching between levels while subscribed updates the header", async function (assert) {
+ this.desktopNotifications.isSubscribed = true;
+
+ await render(
+ <template><PushNotificationSelect @model={{this.model}} /></template>
+ );
+
+ await selectKit(".push-notification-select").expand();
+ await selectKit(".push-notification-select").selectRowByValue("chat_only");
+
+ assert.strictEqual(
+ selectKit(".push-notification-select").header().value(),
+ "chat_only"
+ );
+
+ await selectKit(".push-notification-select").expand();
+ await selectKit(".push-notification-select").selectRowByValue("all");
+
+ assert.strictEqual(
+ selectKit(".push-notification-select").header().value(),
+ "all"
+ );
+ });
+
+ test("reverts to 'none' when the device can't subscribe", async function (assert) {
+ // enable() resolves without actually subscribing (e.g. push service error)
+ this.desktopNotifications.enable = () => {};
+
+ await render(
+ <template><PushNotificationSelect @model={{this.model}} /></template>
+ );
+
+ await selectKit(".push-notification-select").expand();
+ await selectKit(".push-notification-select").selectRowByValue("chat_only");
+
+ assert.strictEqual(
+ selectKit(".push-notification-select").header().value(),
+ "none",
+ "the combobox reverts to none when the subscription can't complete"
+ );
+ assert.strictEqual(
+ this.model.savedFields,
+ null,
+ "nothing is persisted when the subscription can't complete"
+ );
+ });
+});
diff --git a/plugins/chat/assets/javascripts/discourse/connectors/user-preferences-notifications/chat-notifications.gjs b/plugins/chat/assets/javascripts/discourse/connectors/user-preferences-notifications/chat-notifications.gjs
new file mode 100644
index 00000000000..d28b2d0c54e
--- /dev/null
+++ b/plugins/chat/assets/javascripts/discourse/connectors/user-preferences-notifications/chat-notifications.gjs
@@ -0,0 +1,126 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { hash } from "@ember/helper";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import PreferenceCheckbox from "discourse/components/preference-checkbox";
+import ComboBox from "discourse/select-kit/components/combo-box";
+import { i18n } from "discourse-i18n";
+import {
+ HEADER_INDICATOR_PREFERENCE_ALL_NEW,
+ HEADER_INDICATOR_PREFERENCE_DM_AND_MENTIONS,
+ HEADER_INDICATOR_PREFERENCE_NEVER,
+ HEADER_INDICATOR_PREFERENCE_ONLY_MENTIONS,
+} from "discourse/plugins/chat/discourse/lib/chat-constants";
+import {
+ CHAT_SOUNDS,
+ normalizeChatSoundName,
+} from "discourse/plugins/chat/discourse/services/chat-audio-manager";
+
+export default class ChatNotifications extends Component {
+ static shouldRender(args, { siteSettings }) {
+ return siteSettings.chat_enabled && args.model?.user_option?.chat_enabled;
+ }
+
+ @service chatAudioManager;
+
+ @tracked chatSound;
+ @tracked headerIndicatorPreference;
+
+ constructor() {
+ super(...arguments);
+ this.chatSound = normalizeChatSoundName(this.userOption.chat_sound);
+ this.headerIndicatorPreference =
+ this.userOption.chat_header_indicator_preference;
+ }
+
+ get model() {
+ return this.args.outletArgs.model;
+ }
+
+ get userOption() {
+ return this.model.user_option;
+ }
+
+ get chatSounds() {
+ return Object.keys(CHAT_SOUNDS).map((value) => ({
+ name: i18n(`chat.sounds.${value}`),
+ value,
+ }));
+ }
+
+ get headerIndicatorOptions() {
+ return [
+ {
+ name: i18n("chat.header_indicator_preference.all_new"),
+ value: HEADER_INDICATOR_PREFERENCE_ALL_NEW,
+ },
+ {
+ name: i18n("chat.header_indicator_preference.dm_and_mentions"),
+ value: HEADER_INDICATOR_PREFERENCE_DM_AND_MENTIONS,
+ },
+ {
+ name: i18n("chat.header_indicator_preference.only_mentions"),
+ value: HEADER_INDICATOR_PREFERENCE_ONLY_MENTIONS,
+ },
+ {
+ name: i18n("chat.header_indicator_preference.never"),
+ value: HEADER_INDICATOR_PREFERENCE_NEVER,
+ },
+ ];
+ }
+
+ @action
+ setHeaderIndicatorPreference(value) {
+ this.headerIndicatorPreference = value;
+ this.model.set("user_option.chat_header_indicator_preference", value);
+ }
+
+ @action
+ setChatSound(sound) {
+ if (sound) {
+ this.chatAudioManager?.play(sound, { throttle: false });
+ }
+
+ this.chatSound = sound ?? null;
+ this.model.set("user_option.chat_sound", sound ?? null);
+ }
+
+ <template>
+ <div class="control-group chat-notifications">
+ <label class="control-label">{{i18n
+ "chat.chat_notifications_title"
+ }}</label>
+
+ <PreferenceCheckbox
+ @labelKey="chat.ignore_channel_wide_mention.title"
+ @checked={{this.userOption.ignore_channel_wide_mention}}
+ data-setting-name="chat-ignore-channel-wide-mention"
+ class="pref-chat-ignore-channel-wide-mention"
+ />
+
+ <div class="controls controls-dropdown">
+ <label>{{i18n "chat.sound.title"}}</label>
+ <ComboBox
+ @valueProperty="value"
+ @content={{this.chatSounds}}
+ @value={{this.chatSound}}
+ @options={{hash none="chat.sounds.none"}}
+ @onChange={{this.setChatSound}}
+ class="chat-sound"
+ />
+ </div>
+
+ <div class="controls controls-dropdown">
+ <label>{{i18n "chat.header_indicator_preference.title"}}</label>
+ <ComboBox
+ @valueProperty="value"
+ @content={{this.headerIndicatorOptions}}
+ @value={{this.headerIndicatorPreference}}
+ @onChange={{this.setHeaderIndicatorPreference}}
+ class="chat-header-indicator-preference"
+ />
+ </div>
+ </div>
+ </template>
+}
diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-user-options.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-user-options.js
index 8e7943c7949..df5ec31a3da 100644
--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-user-options.js
+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-user-options.js
@@ -12,15 +12,19 @@ export default {
api.addSaveableUserOption("chat_announce_new_messages");
api.addSaveableUserOption("chat_new_message_sound");
api.addSaveableUserOption("chat_enabled");
- api.addSaveableUserOption("chat_header_indicator_preference");
api.addSaveableUserOption("chat_quick_reaction_type");
api.addSaveableUserOption("chat_quick_reactions_custom");
api.addSaveableUserOption("chat_send_shortcut");
api.addSaveableUserOption("chat_separate_sidebar_mode");
- api.addSaveableUserOption("chat_sound");
- api.addSaveableUserOption("ignore_channel_wide_mention");
- api.addSaveableUserOption("only_chat_push_notifications");
api.addSaveableUserOption("show_thread_title_prompts");
+ // Notification settings (rendered on the notifications preferences tab)
+ api.addSaveableUserOption("chat_header_indicator_preference", {
+ page: "notifications",
+ });
+ api.addSaveableUserOption("chat_sound", { page: "notifications" });
+ api.addSaveableUserOption("ignore_channel_wide_mention", {
+ page: "notifications",
+ });
// Email settings
api.addSaveableUserOption("chat_email_frequency", { page: "emails" });
}
diff --git a/plugins/chat/assets/javascripts/discourse/lib/chat-constants.js b/plugins/chat/assets/javascripts/discourse/lib/chat-constants.js
index e2af398161b..286004e5d46 100644
--- a/plugins/chat/assets/javascripts/discourse/lib/chat-constants.js
+++ b/plugins/chat/assets/javascripts/discourse/lib/chat-constants.js
@@ -20,12 +20,8 @@ export const CHAT_ATTRS = [
"chat_enabled",
"chat_announce_new_messages",
"chat_new_message_sound",
- "only_chat_push_notifications",
- "ignore_channel_wide_mention",
"show_thread_title_prompts",
- "chat_sound",
"chat_email_frequency",
- "chat_header_indicator_preference",
"chat_separate_sidebar_mode",
"chat_send_shortcut",
"chat_quick_reaction_type",
diff --git a/plugins/chat/assets/javascripts/discourse/templates/preferences/chat.gjs b/plugins/chat/assets/javascripts/discourse/templates/preferences/chat.gjs
index 2a02efd9a79..aab525e4a14 100644
--- a/plugins/chat/assets/javascripts/discourse/templates/preferences/chat.gjs
+++ b/plugins/chat/assets/javascripts/discourse/templates/preferences/chat.gjs
@@ -2,7 +2,6 @@ import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { fn } from "@ember/helper";
import { action } from "@ember/object";
-import { service } from "@ember/service";
import EmojiPicker from "discourse/components/emoji-picker";
import Form from "discourse/components/form";
import { popupAjaxError } from "discourse/lib/ajax-error";
@@ -21,19 +20,9 @@ import {
CHAT_SEPARATE_SIDEBAR_MODE_ALWAYS,
CHAT_SEPARATE_SIDEBAR_MODE_FULLSCREEN,
CHAT_SEPARATE_SIDEBAR_MODE_NEVER,
- HEADER_INDICATOR_PREFERENCE_ALL_NEW,
- HEADER_INDICATOR_PREFERENCE_DM_AND_MENTIONS,
- HEADER_INDICATOR_PREFERENCE_NEVER,
- HEADER_INDICATOR_PREFERENCE_ONLY_MENTIONS,
} from "discourse/plugins/chat/discourse/lib/chat-constants";
-import {
- CHAT_SOUNDS,
- normalizeChatSoundName,
-} from "discourse/plugins/chat/discourse/services/chat-audio-manager";
export default class Chat extends Component {
- @service chatAudioManager;
-
@tracked saved = false;
get chatQuickReactionTypes() {
@@ -64,27 +53,6 @@ export default class Chat extends Component {
];
}
- get headerIndicatorOptions() {
- return [
- {
- name: i18n("chat.header_indicator_preference.all_new"),
- value: HEADER_INDICATOR_PREFERENCE_ALL_NEW,
- },
- {
- name: i18n("chat.header_indicator_preference.dm_and_mentions"),
- value: HEADER_INDICATOR_PREFERENCE_DM_AND_MENTIONS,
- },
- {
- name: i18n("chat.header_indicator_preference.only_mentions"),
- value: HEADER_INDICATOR_PREFERENCE_ONLY_MENTIONS,
- },
- {
- name: i18n("chat.header_indicator_preference.never"),
- value: HEADER_INDICATOR_PREFERENCE_NEVER,
- },
- ];
- }
-
get chatSeparateSidebarModeOptions() {
return [
{
@@ -102,12 +70,6 @@ export default class Chat extends Component {
];
}
- get chatSounds() {
- return Object.keys(CHAT_SOUNDS).map((value) => {
- return { name: i18n(`chat.sounds.${value}`), value };
- });
- }
-
get formData() {
const userOption = this.args.model.user_option;
const emojis = (
@@ -119,13 +81,8 @@ export default class Chat extends Component {
chat_enabled: userOption.chat_enabled,
chat_quick_reaction_type: userOption.chat_quick_reaction_type,
chat_quick_reactions_custom: emojis,
- only_chat_push_notifications: userOption.only_chat_push_notifications,
- ignore_channel_wide_mention: userOption.ignore_channel_wide_mention,
chat_announce_new_messages: userOption.chat_announce_new_messages,
chat_new_message_sound: userOption.chat_new_message_sound,
- chat_sound: normalizeChatSoundName(userOption.chat_sound),
- chat_header_indicator_preference:
- userOption.chat_header_indicator_preference,
chat_separate_sidebar_mode: userOption.chat_separate_sidebar_mode,
chat_send_shortcut: userOption.chat_send_shortcut,
};
@@ -138,14 +95,6 @@ export default class Chat extends Component {
field.set(newValue);
}
- @action
- handleChatSoundSet(sound, { set, name }) {
- if (sound) {
- this.chatAudioManager?.play(sound, { throttle: false });
- }
- set(name, sound == null ? null : sound);
- }
-
@action
handleSubmit(data) {
this.saved = false;
@@ -189,74 +138,6 @@ export default class Chat extends Component {
<field.Control @value={{field.value}} />
</form.Field>
- <form.Section @title={{i18n "chat.chat_notifications_title"}}>
- <form.Field
- @title={{i18n "chat.only_chat_push_notifications.title"}}
- @name="only_chat_push_notifications"
- @format="large"
- @type="checkbox"
- as |field|
- >
- <field.Control @value={{field.value}} />
- </form.Field>
- <form.Field
- @title={{i18n "chat.ignore_channel_wide_mention.title"}}
- @name="ignore_channel_wide_mention"
- @format="large"
- @type="checkbox"
- as |field|
- >
- <field.Control @value={{field.value}} />
- </form.Field>
-
- <form.Field
- @title={{i18n "chat.sound.title"}}
- @name="chat_sound"
- @format="large"
- @onSet={{this.handleChatSoundSet}}
- @type="select"
- as |field|
- >
- <field.Control @includeNone={{true}} as |select|>
- {{#each this.chatSounds as |sound|}}
- <select.Option @value={{sound.value}}>
- {{sound.name}}
- </select.Option>
- {{/each}}
- </field.Control>
- </form.Field>
-
- <form.Field
- @title={{i18n "chat.header_indicator_preference.title"}}
- @name="chat_header_indicator_preference"
- @format="large"
- @type="select"
- as |field|
- >
- <field.Control @includeNone={{false}} as |select|>
- {{#each this.headerIndicatorOptions as |option|}}
- <select.Option @value={{option.value}}>
- {{option.name}}
- </select.Option>
- {{/each}}
- </field.Control>
- </form.Field>
- <form.Field
- @title={{i18n "chat.separate_sidebar_mode.title"}}
- @name="chat_separate_sidebar_mode"
- @format="large"
- @type="select"
- as |field|
- >
- <field.Control @includeNone={{false}} as |select|>
- {{#each this.chatSeparateSidebarModeOptions as |option|}}
- <select.Option @value={{option.value}}>
- {{option.name}}
- </select.Option>
- {{/each}}
- </field.Control>
- </form.Field>
- </form.Section>
<form.Section @title={{i18n "chat.personalization_title"}}>
<form.Field
@title={{i18n "chat.quick_reaction_type.title"}}
@@ -309,6 +190,21 @@ export default class Chat extends Component {
{{/each}}
</field.Control>
</form.Field>
+ <form.Field
+ @title={{i18n "chat.separate_sidebar_mode.title"}}
+ @name="chat_separate_sidebar_mode"
+ @format="large"
+ @type="select"
+ as |field|
+ >
+ <field.Control @includeNone={{false}} as |select|>
+ {{#each this.chatSeparateSidebarModeOptions as |option|}}
+ <select.Option @value={{option.value}}>
+ {{option.name}}
+ </select.Option>
+ {{/each}}
+ </field.Control>
+ </form.Field>
</form.Section>
<form.Section @title={{i18n "chat.accessibility_title"}}>
<form.Field
diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.yml
index 00ccace9b9d..fcde0c259ad 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -286,8 +286,6 @@ en:
no_public_channels_cta: "Browse channels"
kicked_from_channel: "You can no longer access this channel."
chat_notifications_title: "Chat notifications"
- only_chat_push_notifications:
- title: "Only send chat push notifications"
personalization_title: "Personalization"
accessibility_title: "Accessibility"
ignore_channel_wide_mention:
diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb
index 59355f1dbfe..59428e681e5 100644
--- a/plugins/chat/plugin.rb
+++ b/plugins/chat/plugin.rb
@@ -86,7 +86,6 @@ after_initialize do
UserUpdater::OPTION_ATTR.push(:chat_enabled)
UserUpdater::OPTION_ATTR.push(:chat_quick_reaction_type)
UserUpdater::OPTION_ATTR.push(:chat_quick_reactions_custom)
- UserUpdater::OPTION_ATTR.push(:only_chat_push_notifications)
UserUpdater::OPTION_ATTR.push(:chat_sound)
UserUpdater::OPTION_ATTR.push(:ignore_channel_wide_mention)
UserUpdater::OPTION_ATTR.push(:show_thread_title_prompts)
@@ -97,6 +96,17 @@ after_initialize do
UserUpdater::OPTION_ATTR.push(:chat_separate_sidebar_mode)
UserUpdater::OPTION_ATTR.push(:chat_send_shortcut)
+ # When a user opts into chat-only push notifications, suppress every push that
+ # isn't a chat message/mention. Registered here (rather than in core) so it's
+ # only active while chat is enabled, and runs alongside core's other filters.
+ register_push_notification_filter do |user, payload|
+ if user.user_option.push_notification_level_chat_only? && user.user_option.chat_enabled
+ payload[:notification_type].in?(::Notification.types.values_at(:chat_mention, :chat_message))
+ else
+ true
+ end
+ end
+
register_reviewable_type Chat::ReviewableMessage
if respond_to?(:register_discourse_workflows_node)
@@ -292,10 +302,6 @@ after_initialize do
include_condition: -> { object.chat_sound.present? },
) { object.chat_sound }
- add_to_serializer(:user_option, :only_chat_push_notifications) do
- object.only_chat_push_notifications
- end
-
add_to_serializer(:user_option, :ignore_channel_wide_mention) do
object.ignore_channel_wide_mention
end
@@ -410,14 +416,6 @@ after_initialize do
end
end
- register_push_notification_filter do |user, payload|
- if user.user_option.only_chat_push_notifications && user.user_option.chat_enabled
- payload[:notification_type].in?(::Notification.types.values_at(:chat_mention, :chat_message))
- else
- true
- end
- end
-
on(:user_seen) do |user|
if user.last_seen_at == user.first_seen_at
Chat::AutoJoinChannels.call(params: { user_id: user.id })
diff --git a/plugins/chat/spec/lib/chat/push_notification_filter_spec.rb b/plugins/chat/spec/lib/chat/push_notification_filter_spec.rb
new file mode 100644
index 00000000000..9ed17cb2c92
--- /dev/null
+++ b/plugins/chat/spec/lib/chat/push_notification_filter_spec.rb
@@ -0,0 +1,83 @@
+# frozen_string_literal: true
+
+RSpec.describe PostAlerter do
+ fab!(:user)
+ fab!(:topic)
+ fab!(:post) { Fabricate(:post, topic: topic) }
+
+ before do
+ SiteSetting.chat_enabled = true
+ SiteSetting.allowed_user_api_push_urls = "https://site2.com/push"
+
+ 2.times do |i|
+ client = Fabricate(:user_api_key_client, client_id: "xxx#{i}", application_name: "iPhone#{i}")
+ Fabricate(
+ :user_api_key,
+ user: user,
+ scopes: ["notifications"].map { |name| UserApiKeyScope.new(name: name) },
+ push_url: "https://site2.com/push",
+ user_api_key_client_id: client.id,
+ )
+ end
+ end
+
+ def push(notification_type)
+ PostAlerter.push_notification(
+ user,
+ {
+ notification_type: notification_type,
+ post_number: 1,
+ topic_id: topic.id,
+ post_id: post.id,
+ excerpt: "excerpt",
+ username: "someone",
+ },
+ )
+ end
+
+ context "when push_notification_level is chat_only" do
+ before { user.user_option.update!(push_notification_level: :chat_only) }
+
+ it "suppresses non-chat push notifications" do
+ expect { push(Notification.types[:mentioned]) }.not_to change {
+ Jobs::DeliverPushNotification.jobs.count
+ }
+ end
+
+ it "still delivers chat push notifications" do
+ expect { push(Notification.types[:chat_mention]) }.to change {
+ Jobs::DeliverPushNotification.jobs.count
+ }.by(1)
+ end
+
+ context "when the user has disabled chat" do
+ before { user.user_option.update!(chat_enabled: false) }
+
+ it "delivers all push notifications" do
+ expect { push(Notification.types[:mentioned]) }.to change {
+ Jobs::DeliverPushNotification.jobs.count
+ }.by(1)
+ end
+ end
+
+ context "when chat is disabled site-wide" do
+ before { SiteSetting.chat_enabled = false }
+
+ it "delivers all push notifications" do
+ expect { push(Notification.types[:mentioned]) }.to change {
+ Jobs::DeliverPushNotification.jobs.count
+ }.by(1)
+ end
+ end
+ end
+
+ context "when push_notification_level is all" do
+ before { user.user_option.update!(push_notification_level: :all) }
+
+ it "delivers non-chat push notifications" do
+ expect { push(Notification.types[:mentioned]) }.to change {
+ Jobs::DeliverPushNotification.jobs.count
+ }.by(1)
+ end
+ end
+end
diff --git a/plugins/chat/spec/system/user_chat_preferences_spec.rb b/plugins/chat/spec/system/user_chat_preferences_spec.rb
index c00542a462d..3f3538b6248 100644
--- a/plugins/chat/spec/system/user_chat_preferences_spec.rb
+++ b/plugins/chat/spec/system/user_chat_preferences_spec.rb
@@ -88,38 +88,6 @@ RSpec.describe "User chat preferences" do
end
end
- shared_examples "select and save" do
- it "can select and save" do
- user_preferences_chat_page.visit
- form.field(field_name).select(val)
- form.submit
- user_preferences_chat_page.visit
-
- expect(form.field(field_name).value).to eq val
- end
- end
-
- describe "chat sound" do
- include_examples "select and save" do
- let(:field_name) { "chat_sound" }
- let(:val) { "classic" }
- end
- end
-
- describe "header_indicator_preference" do
- include_examples "select and save" do
- let(:field_name) { "chat_header_indicator_preference" }
- let(:val) { "dm_and_mentions" }
- end
- end
-
- describe "separate sidebar mode" do
- include_examples "select and save" do
- let(:field_name) { "chat_separate_sidebar_mode" }
- let(:val) { "fullscreen" }
- end
- end
-
it "can select send shorcut sidebar mode" do
user_preferences_chat_page.visit
form.field("chat_send_shortcut").select("meta_enter")
@@ -131,6 +99,15 @@ RSpec.describe "User chat preferences" do
).to be_checked
end
+ it "can select and save separate sidebar mode" do
+ user_preferences_chat_page.visit
+ form.field("chat_separate_sidebar_mode").select("fullscreen")
+ form.submit
+ user_preferences_chat_page.visit
+
+ expect(form.field("chat_separate_sidebar_mode").value).to eq("fullscreen")
+ end
+
context "as an admin on another user's preferences" do
fab!(:current_user, :admin)
fab!(:user_1, :user)
diff --git a/plugins/chat/spec/system/user_notification_preferences_spec.rb b/plugins/chat/spec/system/user_notification_preferences_spec.rb
new file mode 100644
index 00000000000..dc5b03288eb
--- /dev/null
+++ b/plugins/chat/spec/system/user_notification_preferences_spec.rb
@@ -0,0 +1,77 @@
+# frozen_string_literal: true
+
+RSpec.describe "User notification preferences | Chat notifications" do
+ fab!(:current_user, :user)
+
+ before do
+ chat_system_bootstrap
+ sign_in(current_user)
+ end
+
+ def visit_notifications
+ page.visit("/my/preferences/notifications")
+ end
+
+ def combo(selector)
+ PageObjects::Components::SelectKit.new(selector)
+ end
+
+ def save
+ find(".save-changes").click
+ expect(page).to have_css(".saved")
+ end
+
+ context "when chat is disabled site-wide" do
+ before { SiteSetting.chat_enabled = false }
+
+ it "does not render the chat notifications section" do
+ visit_notifications
+
+ expect(page).to have_no_css(".control-group.chat-notifications")
+ end
+ end
+
+ context "when the user has disabled chat" do
+ before { current_user.user_option.update!(chat_enabled: false) }
+
+ it "does not render the chat notifications section" do
+ visit_notifications
+
+ expect(page).to have_no_css(".control-group.chat-notifications")
+ end
+ end
+
+ it "renders the chat notifications section" do
+ visit_notifications
+
+ expect(page).to have_css(".control-group.chat-notifications")
+ end
+
+ it "can change and persist the chat notification settings" do
+ visit_notifications
+
+ combo(".chat-header-indicator-preference").expand
+ combo(".chat-header-indicator-preference").select_row_by_value("dm_and_mentions")
+
+ combo(".chat-sound").expand
+ combo(".chat-sound").select_row_by_value("retro")
+
+ save
+ visit_notifications
+
+ expect(combo(".chat-header-indicator-preference").value).to eq("dm_and_mentions")
+ expect(combo(".chat-sound").value).to eq("retro")
+ end
+
+ it "can toggle and persist ignore channel-wide mentions" do
+ current_user.user_option.update!(ignore_channel_wide_mention: false)
+ visit_notifications
+
+ find(".pref-chat-ignore-channel-wide-mention input[type=checkbox]").click
+ save
+ visit_notifications
+
+ expect(page).to have_css(".pref-chat-ignore-channel-wide-mention input[type=checkbox]:checked")
+ expect(current_user.reload.user_option.ignore_channel_wide_mention).to eq(true)
+ end
+end
diff --git a/spec/requests/api/schemas/json/user_get_response.json b/spec/requests/api/schemas/json/user_get_response.json
index 6233ecf162d..485108ed769 100644
--- a/spec/requests/api/schemas/json/user_get_response.json
+++ b/spec/requests/api/schemas/json/user_get_response.json
@@ -769,6 +769,9 @@
"notify_on_linked_posts": {
"type": "boolean"
},
+ "push_notification_level": {
+ "type": "string"
+ },
"enable_upcoming_change_available_notifications": {
"type": "boolean"
},
@@ -878,6 +881,7 @@
"email_in_reply_to",
"like_notification_frequency",
"notify_on_linked_posts",
+ "push_notification_level",
"enable_upcoming_change_available_notifications",
"include_tl0_in_digests",
"theme_ids",