diff --git a/src/Notifier.js b/src/Notifier.js index d5810fe30d..2aad99875c 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -120,11 +120,11 @@ const Notifier = { }; }, - _playAudioNotification: function(ev, room) { - this.getSoundForRoom(room.roomId).then((sound) => { - console.log(`Got sound ${sound.name || "default"} for ${room.roomId}`); - // XXX: How do we ensure this is a sound file and not - // going to be exploited? + _playAudioNotification: async function(ev, room) { + const sound = SettingsStore.isFeatureEnabled("feature_notification_sounds") ? await this.getSoundForRoom(room.roomId) : null; + console.log(`Got sound ${sound.name || "default"} for ${room.roomId}`); + // XXX: How do we ensure this is a sound file and not going to be exploited? + try { const selector = document.querySelector(sound ? `audio[src='${sound.url}']` : "#messageAudio"); let audioElement = selector; if (!selector) { @@ -139,9 +139,9 @@ const Notifier = { document.body.appendChild(audioElement); } audioElement.play(); - }).catch((ex) => { + } catch (ex) { console.warn("Caught error when trying to fetch room notification sound:", ex); - }); + } }, start: function() { diff --git a/src/components/views/dialogs/RoomSettingsDialog.js b/src/components/views/dialogs/RoomSettingsDialog.js index caed958003..180148aead 100644 --- a/src/components/views/dialogs/RoomSettingsDialog.js +++ b/src/components/views/dialogs/RoomSettingsDialog.js @@ -25,6 +25,7 @@ import SecurityRoomSettingsTab from "../settings/tabs/room/SecurityRoomSettingsT import NotificationSettingsTab from "../settings/tabs/room/NotificationSettingsTab"; import sdk from "../../../index"; import MatrixClientPeg from "../../../MatrixClientPeg"; +import SettingsStore from '../../../settings/SettingsStore'; export default class RoomSettingsDialog extends React.Component { static propTypes = { @@ -50,11 +51,15 @@ export default class RoomSettingsDialog extends React.Component { "mx_RoomSettingsDialog_rolesIcon", , )); - tabs.push(new Tab( - _td("Notifications"), - "mx_RoomSettingsDialog_rolesIcon", - , - )); + + if (SettingsStore.isFeatureEnabled("feature_notification_sounds")) { + tabs.push(new Tab( + _td("Notifications"), + "mx_RoomSettingsDialog_rolesIcon", + , + )); + } + tabs.push(new Tab( _td("Advanced"), "mx_RoomSettingsDialog_warningIcon", diff --git a/src/components/views/settings/tabs/room/NotificationSettingsTab.js b/src/components/views/settings/tabs/room/NotificationSettingsTab.js index 062d54988a..6199804cde 100644 --- a/src/components/views/settings/tabs/room/NotificationSettingsTab.js +++ b/src/components/views/settings/tabs/room/NotificationSettingsTab.js @@ -115,7 +115,7 @@ export default class NotificationsSettingsTab extends React.Component {
{_t("Sounds")}
- {_t("Notification sound")}: {this.state.currentSound} + {_t("Custom Notification Sounds")}: {this.state.currentSound}

{_t("Set a new custom sound")}

diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 7f94bdc9cd..feeff019c0 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1616,7 +1616,7 @@ "Failed to remove tag %(tagName)s from room": "Failed to remove tag %(tagName)s from room", "Failed to add tag %(tagName)s to room": "Failed to add tag %(tagName)s to room", "Sounds": "Sounds", - "Notification sound": "Notification sound", + "Custom Notification Sounds": "Notification sound", "Set a new custom sound": "Set a new custom sound", "Reset to default sound": "Reset to default sound" } diff --git a/src/settings/Settings.js b/src/settings/Settings.js index b40213e514..b0014ae4b6 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -119,6 +119,12 @@ export const SETTINGS = { supportedLevels: LEVELS_FEATURE, default: false, }, + "feature_notification_sounds": { + isFeature: true, + displayName: _td("Custom Notification Sounds"), + supportedLevels: LEVELS_FEATURE, + default: false, + }, "MessageComposerInput.suggestEmoji": { supportedLevels: LEVELS_ACCOUNT_SETTINGS, displayName: _td('Enable Emoji suggestions while typing'),