Fix URL preview options

Signed-off-by: Travis Ralston <travpc@gmail.com>
This commit is contained in:
Travis Ralston 2017-10-30 19:49:44 -06:00
parent 72517f95bb
commit 9c846e4dd9
4 changed files with 19 additions and 4 deletions

View File

@ -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}
/>
);
}

View File

@ -55,7 +55,8 @@ module.exports = React.createClass({
<label>
<SettingsCheckbox name="urlPreviewsEnabled"
level="room"
roomId={this.props.room.roomId} />
roomId={this.props.room.roomId}
isExplicit={true} />
</label>
);
} else {

View File

@ -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);

View File

@ -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);
}