Stick behind a feature flag

pull/21833/head
Will Hunt 2019-04-21 18:01:26 +01:00
parent 776210c135
commit 0f2cd6ea73
5 changed files with 25 additions and 14 deletions

View File

@ -120,11 +120,11 @@ const Notifier = {
}; };
}, },
_playAudioNotification: function(ev, room) { _playAudioNotification: async function(ev, room) {
this.getSoundForRoom(room.roomId).then((sound) => { const sound = SettingsStore.isFeatureEnabled("feature_notification_sounds") ? await this.getSoundForRoom(room.roomId) : null;
console.log(`Got sound ${sound.name || "default"} for ${room.roomId}`); console.log(`Got sound ${sound.name || "default"} for ${room.roomId}`);
// XXX: How do we ensure this is a sound file and not // XXX: How do we ensure this is a sound file and not going to be exploited?
// going to be exploited? try {
const selector = document.querySelector(sound ? `audio[src='${sound.url}']` : "#messageAudio"); const selector = document.querySelector(sound ? `audio[src='${sound.url}']` : "#messageAudio");
let audioElement = selector; let audioElement = selector;
if (!selector) { if (!selector) {
@ -139,9 +139,9 @@ const Notifier = {
document.body.appendChild(audioElement); document.body.appendChild(audioElement);
} }
audioElement.play(); audioElement.play();
}).catch((ex) => { } catch (ex) {
console.warn("Caught error when trying to fetch room notification sound:", ex); console.warn("Caught error when trying to fetch room notification sound:", ex);
}); }
}, },
start: function() { start: function() {

View File

@ -25,6 +25,7 @@ import SecurityRoomSettingsTab from "../settings/tabs/room/SecurityRoomSettingsT
import NotificationSettingsTab from "../settings/tabs/room/NotificationSettingsTab"; import NotificationSettingsTab from "../settings/tabs/room/NotificationSettingsTab";
import sdk from "../../../index"; import sdk from "../../../index";
import MatrixClientPeg from "../../../MatrixClientPeg"; import MatrixClientPeg from "../../../MatrixClientPeg";
import SettingsStore from '../../../settings/SettingsStore';
export default class RoomSettingsDialog extends React.Component { export default class RoomSettingsDialog extends React.Component {
static propTypes = { static propTypes = {
@ -50,11 +51,15 @@ export default class RoomSettingsDialog extends React.Component {
"mx_RoomSettingsDialog_rolesIcon", "mx_RoomSettingsDialog_rolesIcon",
<RolesRoomSettingsTab roomId={this.props.roomId} />, <RolesRoomSettingsTab roomId={this.props.roomId} />,
)); ));
tabs.push(new Tab(
_td("Notifications"), if (SettingsStore.isFeatureEnabled("feature_notification_sounds")) {
"mx_RoomSettingsDialog_rolesIcon", tabs.push(new Tab(
<NotificationSettingsTab roomId={this.props.roomId} />, _td("Notifications"),
)); "mx_RoomSettingsDialog_rolesIcon",
<NotificationSettingsTab roomId={this.props.roomId} />,
));
}
tabs.push(new Tab( tabs.push(new Tab(
_td("Advanced"), _td("Advanced"),
"mx_RoomSettingsDialog_warningIcon", "mx_RoomSettingsDialog_warningIcon",

View File

@ -115,7 +115,7 @@ export default class NotificationsSettingsTab extends React.Component {
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'> <div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
<span className='mx_SettingsTab_subheading'>{_t("Sounds")}</span> <span className='mx_SettingsTab_subheading'>{_t("Sounds")}</span>
<div> <div>
<span>{_t("Notification sound")}: <code>{this.state.currentSound}</code></span> <span>{_t("Custom Notification Sounds")}: <code>{this.state.currentSound}</code></span>
</div> </div>
<div> <div>
<h3>{_t("Set a new custom sound")}</h3> <h3>{_t("Set a new custom sound")}</h3>

View File

@ -1616,7 +1616,7 @@
"Failed to remove tag %(tagName)s from room": "Failed to remove tag %(tagName)s from room", "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", "Failed to add tag %(tagName)s to room": "Failed to add tag %(tagName)s to room",
"Sounds": "Sounds", "Sounds": "Sounds",
"Notification sound": "Notification sound", "Custom Notification Sounds": "Notification sound",
"Set a new custom sound": "Set a new custom sound", "Set a new custom sound": "Set a new custom sound",
"Reset to default sound": "Reset to default sound" "Reset to default sound": "Reset to default sound"
} }

View File

@ -119,6 +119,12 @@ export const SETTINGS = {
supportedLevels: LEVELS_FEATURE, supportedLevels: LEVELS_FEATURE,
default: false, default: false,
}, },
"feature_notification_sounds": {
isFeature: true,
displayName: _td("Custom Notification Sounds"),
supportedLevels: LEVELS_FEATURE,
default: false,
},
"MessageComposerInput.suggestEmoji": { "MessageComposerInput.suggestEmoji": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS, supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Enable Emoji suggestions while typing'), displayName: _td('Enable Emoji suggestions while typing'),