From 9c846e4dd938bda491bb95988bcbdb4bc7daea94 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 30 Oct 2017 19:49:44 -0600 Subject: [PATCH] Fix URL preview options Signed-off-by: Travis Ralston --- src/components/views/elements/SettingsCheckbox.js | 6 +++++- .../views/room_settings/UrlPreviewSettings.js | 3 ++- src/settings/RoomSettingsHandler.js | 2 +- src/settings/SettingsStore.js | 12 +++++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/views/elements/SettingsCheckbox.js b/src/components/views/elements/SettingsCheckbox.js index d9b293b086..a39b400183 100644 --- a/src/components/views/elements/SettingsCheckbox.js +++ b/src/components/views/elements/SettingsCheckbox.js @@ -26,6 +26,7 @@ module.exports = React.createClass({ roomId: React.PropTypes.string, // for per-room settings label: React.PropTypes.string, // untranslated onChange: React.PropTypes.func, + isExplicit: React.PropTypes.bool, // If group is supplied, then this will create a radio button instead. group: React.PropTypes.string, @@ -41,7 +42,8 @@ module.exports = React.createClass({ }, render: function() { - let val = SettingsStore.getValueAt(this.props.level, this.props.name, this.props.roomId); + const val = SettingsStore.getValueAt(this.props.level, this.props.name, this.props.roomId, this.props.isExplicit); + const canChange = SettingsStore.canSetValue(this.props.name, this.props.roomId, this.props.level); let label = this.props.label; if (!label) label = SettingsStore.getDisplayName(this.props.name, this.props.level); @@ -54,6 +56,7 @@ module.exports = React.createClass({ type="checkbox" defaultChecked={val} onChange={this.onChange} + disabled={!canChange} /> ); if (this.props.group) { @@ -64,6 +67,7 @@ module.exports = React.createClass({ value={this.props.value} checked={val === this.props.value} onChange={this.onChange} + disabled={!canChange} /> ); } diff --git a/src/components/views/room_settings/UrlPreviewSettings.js b/src/components/views/room_settings/UrlPreviewSettings.js index c0e90c9ed6..cfd75537ef 100644 --- a/src/components/views/room_settings/UrlPreviewSettings.js +++ b/src/components/views/room_settings/UrlPreviewSettings.js @@ -55,7 +55,8 @@ module.exports = React.createClass({ ); } else { diff --git a/src/settings/RoomSettingsHandler.js b/src/settings/RoomSettingsHandler.js index 00e16061ee..8f3f8fa1e4 100644 --- a/src/settings/RoomSettingsHandler.js +++ b/src/settings/RoomSettingsHandler.js @@ -36,7 +36,7 @@ export default class RoomSettingsHandler extends SettingsHandler { if (settingName === "urlPreviewsEnabled") { const content = this._getSettings(roomId, "org.matrix.room.preview_urls"); content['disable'] = !newValue; - return MatrixClientPeg.get().setRoomAccountData(roomId, "org.matrix.room.preview_urls", content); + return MatrixClientPeg.get().sendStateEvent(roomId, "org.matrix.room.preview_urls", content); } const content = this._getSettings(roomId); diff --git a/src/settings/SettingsStore.js b/src/settings/SettingsStore.js index bcaf4e234c..65422404f3 100644 --- a/src/settings/SettingsStore.js +++ b/src/settings/SettingsStore.js @@ -335,9 +335,11 @@ export default class SettingsStore { * look at. * @param {string} settingName The name of the setting to read. * @param {String} roomId The room ID to read the setting value in, may be null. + * @param {boolean} explicit If true, this method will not consider other levels, just the one + * provided. Defaults to false. * @return {*} The value, or null if not found. */ - static getValueAt(level, settingName, roomId = null) { + static getValueAt(level, settingName, roomId = null, explicit = false) { const minIndex = LEVEL_ORDER.indexOf(level); if (minIndex === -1) throw new Error("Level " + level + " is not prioritized"); @@ -350,6 +352,12 @@ export default class SettingsStore { const handlers = SettingsStore._getHandlers(settingName); + if (explicit) { + let handler = handlers[level]; + if (!handler) return null; + return handler.getValue(settingName, roomId); + } + for (let i = minIndex; i < LEVEL_ORDER.length; i++) { let handler = handlers[LEVEL_ORDER[i]]; if (!handler) continue; @@ -379,6 +387,8 @@ export default class SettingsStore { throw new Error("Setting " + settingName + " does not have a handler for " + level); } + console.log("Setting " + settingName +" in " + roomId +" at " + level +" to " + value); + if (!handler.canSetValue(settingName, roomId)) { throw new Error("User cannot set " + settingName + " at " + level + " in " + roomId); }