From ec53b5f5ab3d00593fca3da788ec1bf0c333cac2 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sat, 26 May 2018 21:21:06 -0600 Subject: [PATCH] Expose at-room power level setting Fixes https://github.com/vector-im/riot-web/issues/5835 Signed-off-by: Travis Ralston --- src/components/views/rooms/RoomSettings.js | 27 ++++++++++++++++++++-- src/i18n/strings/en_EN.json | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index 059e07ffdb..0ccfa23bf3 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -395,7 +395,17 @@ module.exports = React.createClass({ powerLevels["events"] = Object.assign({}, this.state.powerLevels["events"] || {}); powerLevels["events"][powerLevelKey.slice(eventsLevelPrefix.length)] = value; } else { - powerLevels[powerLevelKey] = value; + const keyPath = powerLevelKey.split('.'); + let parentObj; + let currentObj = powerLevels; + for (const key of keyPath) { + if (!currentObj[key]) { + currentObj[key] = {}; + } + parentObj = currentObj; + currentObj = currentObj[key]; + } + parentObj[keyPath[keyPath.length - 1]] = value; } this.setState({ powerLevels, @@ -664,6 +674,10 @@ module.exports = React.createClass({ desc: _t('To remove other users\' messages, you must be a'), defaultValue: 50, }, + "notifications.room": { + desc: _t('To notify everyone in the room, you must be a'), + defaultValue: 50, + }, }; const banLevel = parseIntWithDefault(powerLevels.ban, powerLevelDescriptors.ban.defaultValue); @@ -865,7 +879,16 @@ module.exports = React.createClass({ const powerSelectors = Object.keys(powerLevelDescriptors).map((key, index) => { const descriptor = powerLevelDescriptors[key]; - const value = parseIntWithDefault(powerLevels[key], descriptor.defaultValue); + const keyPath = key.split('.'); + let currentObj = powerLevels; + for (const prop of keyPath) { + if (currentObj === undefined) { + break; + } + currentObj = currentObj[prop]; + } + + const value = parseIntWithDefault(currentObj, descriptor.defaultValue); return
{ descriptor.desc } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index bf9e395bee..8698e6108f 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -491,6 +491,7 @@ "To kick users, you must be a": "To kick users, you must be a", "To ban users, you must be a": "To ban users, you must be a", "To remove other users' messages, you must be a": "To remove other users' messages, you must be a", + "To notify everyone in the room, you must be a": "To notify everyone in the room, you must be a", "No users have specific privileges in this room": "No users have specific privileges in this room", "%(user)s is a %(userRole)s": "%(user)s is a %(userRole)s", "Privileged Users": "Privileged Users",