Skip to content

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

UX: Add a preview button for the chat notification sound

Jake Goldsborough421f12f79f1e
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
index d28b2d0c54e..000b077aa73 100644
--- 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
@@ -5,6 +5,7 @@ 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 DButton from "discourse/ui-kit/d-button";
import { i18n } from "discourse-i18n";
import {
HEADER_INDICATOR_PREFERENCE_ALL_NEW,
@@ -86,6 +87,11 @@ export default class ChatNotifications extends Component {
this.model.set("user_option.chat_sound", sound ?? null);
}
+ @action
+ previewChatSound() {
+ this.chatAudioManager?.play(this.chatSound, { throttle: false });
+ }
+
<template>
<div class="control-group chat-notifications">
<label class="control-label">{{i18n
@@ -101,14 +107,24 @@ export default class ChatNotifications extends Component {
<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 class="chat-sound-controls">
+ <ComboBox
+ @valueProperty="value"
+ @content={{this.chatSounds}}
+ @value={{this.chatSound}}
+ @options={{hash none="chat.sounds.none"}}
+ @onChange={{this.setChatSound}}
+ class="chat-sound"
+ />
+ {{#if this.chatSound}}
+ <DButton
+ @icon="play"
+ @action={{this.previewChatSound}}
+ @title="chat.sound.preview"
+ class="btn-flat chat-sound-preview"
+ />
+ {{/if}}
+ </div>
</div>
<div class="controls controls-dropdown">
diff --git a/plugins/chat/assets/stylesheets/common/chat-preferences.scss b/plugins/chat/assets/stylesheets/common/chat-preferences.scss
new file mode 100644
index 00000000000..f39f52dc5a5
--- /dev/null
+++ b/plugins/chat/assets/stylesheets/common/chat-preferences.scss
@@ -0,0 +1,7 @@
+.chat-notifications {
+ .chat-sound-controls {
+ display: flex;
+ align-items: center;
+ gap: 0.25em;
+ }
+}
diff --git a/plugins/chat/assets/stylesheets/common/index.scss b/plugins/chat/assets/stylesheets/common/index.scss
index 3245fe9b892..18807183d6d 100644
--- a/plugins/chat/assets/stylesheets/common/index.scss
+++ b/plugins/chat/assets/stylesheets/common/index.scss
@@ -1,6 +1,7 @@
@import "chat-unread-indicator";
@import "chat-height-mixin";
@import "base-common";
+@import "chat-preferences";
@import "chat-drawer-routes";
@import "chat-browse";
@import "chat-disabled";
diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.yml
index cecdb77ba5e..25c9c88b084 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -341,6 +341,7 @@ en:
other: "%{count} new messages"
sound:
title: "Desktop chat notification sound"
+ preview: "Play a preview of the selected sound"
sounds:
none: "None"
classic: "Classic and clean"
diff --git a/plugins/chat/spec/system/user_notification_preferences_spec.rb b/plugins/chat/spec/system/user_notification_preferences_spec.rb
index dc5b03288eb..55e77a6f8fc 100644
--- a/plugins/chat/spec/system/user_notification_preferences_spec.rb
+++ b/plugins/chat/spec/system/user_notification_preferences_spec.rb
@@ -63,6 +63,22 @@ RSpec.describe "User notification preferences | Chat notifications" do
expect(combo(".chat-sound").value).to eq("retro")
end
+ it "shows a sound preview button only while a sound is selected" do
+ visit_notifications
+
+ expect(page).to have_no_css(".chat-sound-preview")
+
+ combo(".chat-sound").expand
+ combo(".chat-sound").select_row_by_value("retro")
+
+ expect(page).to have_css(".chat-sound-preview")
+
+ combo(".chat-sound").expand
+ combo(".chat-sound").select_row_by_name("None")
+
+ expect(page).to have_no_css(".chat-sound-preview")
+ end
+
it "can toggle and persist ignore channel-wide mentions" do
current_user.user_option.update!(ignore_channel_wide_mention: false)
visit_notifications