mirror of https://github.com/vector-im/riot-web
Use settings store
parent
d33df45c5e
commit
776210c135
|
@ -96,28 +96,19 @@ const Notifier = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setRoomSound: function(room, soundData) {
|
getSoundForRoom: async function(roomId) {
|
||||||
return MatrixClientPeg.get().setRoomAccountData(room.roomId, "uk.half-shot.notification.sound", soundData);
|
|
||||||
},
|
|
||||||
|
|
||||||
clearRoomSound: function(room) {
|
|
||||||
return room.setAccountData("uk.half-shot.notification.sound", null);
|
|
||||||
},
|
|
||||||
|
|
||||||
getSoundForRoom: async function(room) {
|
|
||||||
// We do no caching here because the SDK caches the event content
|
// We do no caching here because the SDK caches the event content
|
||||||
// and the browser will cache the sound.
|
// and the browser will cache the sound.
|
||||||
let ev = await room.getAccountData("uk.half-shot.notification.sound");
|
let content = SettingsStore.getValue("notificationSound", roomId);
|
||||||
if (!ev || !ev.getContent()) {
|
if (!content) {
|
||||||
// Check the account data.
|
content = SettingsStore.getValue("notificationSound");
|
||||||
ev = await MatrixClientPeg.get().getAccountData("uk.half-shot.notification.sound");
|
if (!content) {
|
||||||
if (!ev) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const content = ev.getContent();
|
|
||||||
if (!content.url) {
|
if (!content.url) {
|
||||||
console.warn(`${room.roomId} has custom notification sound event, but no url key`);
|
console.warn(`${roomId} has custom notification sound event, but no url key`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +121,7 @@ const Notifier = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_playAudioNotification: function(ev, room) {
|
_playAudioNotification: function(ev, room) {
|
||||||
this.getSoundForRoom(room).then((sound) => {
|
this.getSoundForRoom(room.roomId).then((sound) => {
|
||||||
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?
|
||||||
|
|
|
@ -20,6 +20,7 @@ import {_t} from "../../../../../languageHandler";
|
||||||
import MatrixClientPeg from "../../../../../MatrixClientPeg";
|
import MatrixClientPeg from "../../../../../MatrixClientPeg";
|
||||||
import AccessibleButton from "../../../elements/AccessibleButton";
|
import AccessibleButton from "../../../elements/AccessibleButton";
|
||||||
import Notifier from "../../../../../Notifier";
|
import Notifier from "../../../../../Notifier";
|
||||||
|
import SettingsStore from '../../../../../settings/SettingsStore';
|
||||||
|
|
||||||
export default class NotificationsSettingsTab extends React.Component {
|
export default class NotificationsSettingsTab extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
@ -37,8 +38,7 @@ export default class NotificationsSettingsTab extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
Notifier.getSoundForRoom(this.props.roomId).then((soundData) => {
|
||||||
Notifier.getSoundForRoom(room).then((soundData) => {
|
|
||||||
if (!soundData) {
|
if (!soundData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -79,14 +79,17 @@ export default class NotificationsSettingsTab extends React.Component {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
await SettingsStore.setValue(
|
||||||
|
"notificationSound",
|
||||||
await Notifier.setRoomSound(room, {
|
this.props.roomId,
|
||||||
|
"room-account",
|
||||||
|
{
|
||||||
name: this.state.uploadedFile.name,
|
name: this.state.uploadedFile.name,
|
||||||
type: type,
|
type: type,
|
||||||
size: this.state.uploadedFile.size,
|
size: this.state.uploadedFile.size,
|
||||||
url,
|
url,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
uploadedFile: null,
|
uploadedFile: null,
|
||||||
|
@ -98,8 +101,7 @@ export default class NotificationsSettingsTab extends React.Component {
|
||||||
_clearSound(e) {
|
_clearSound(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
SettingsStore.setValue("notificationSound", this.props.roomId, "room-account", null);
|
||||||
Notifier.clearRoomSound(room);
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
currentSound: "default",
|
currentSound: "default",
|
||||||
|
|
|
@ -26,6 +26,7 @@ import ThemeController from './controllers/ThemeController';
|
||||||
|
|
||||||
// These are just a bunch of helper arrays to avoid copy/pasting a bunch of times
|
// These are just a bunch of helper arrays to avoid copy/pasting a bunch of times
|
||||||
const LEVELS_ROOM_SETTINGS = ['device', 'room-device', 'room-account', 'account', 'config'];
|
const LEVELS_ROOM_SETTINGS = ['device', 'room-device', 'room-account', 'account', 'config'];
|
||||||
|
const LEVELS_ROOM_OR_ACCOUNT = ['room-account', 'account'];
|
||||||
const LEVELS_ROOM_SETTINGS_WITH_ROOM = ['device', 'room-device', 'room-account', 'account', 'config', 'room'];
|
const LEVELS_ROOM_SETTINGS_WITH_ROOM = ['device', 'room-device', 'room-account', 'account', 'config', 'room'];
|
||||||
const LEVELS_ACCOUNT_SETTINGS = ['device', 'account', 'config'];
|
const LEVELS_ACCOUNT_SETTINGS = ['device', 'account', 'config'];
|
||||||
const LEVELS_FEATURE = ['device', 'config'];
|
const LEVELS_FEATURE = ['device', 'config'];
|
||||||
|
@ -315,6 +316,10 @@ export const SETTINGS = {
|
||||||
default: false,
|
default: false,
|
||||||
controller: new NotificationsEnabledController(),
|
controller: new NotificationsEnabledController(),
|
||||||
},
|
},
|
||||||
|
"notificationSound": {
|
||||||
|
supportedLevels: LEVELS_ROOM_OR_ACCOUNT,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
"notificationBodyEnabled": {
|
"notificationBodyEnabled": {
|
||||||
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
|
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
|
||||||
default: true,
|
default: true,
|
||||||
|
|
Loading…
Reference in New Issue