Support a setting for allowed widgets

Hooking this setting up is left as a problem for a different issue.
This commit is contained in:
Travis Ralston 2019-10-29 14:35:35 -06:00
parent 28e0988325
commit 5af6d979c2
2 changed files with 18 additions and 0 deletions

View file

@ -283,6 +283,10 @@ export const SETTINGS = {
supportedLevels: ['account'], supportedLevels: ['account'],
default: true, default: true,
}, },
"allowedWidgets": {
supportedLevels: ['room-account'],
default: {}, // none allowed
},
"analyticsOptIn": { "analyticsOptIn": {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG, supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td('Send analytics data'), displayName: _td('Send analytics data'),

View file

@ -19,6 +19,8 @@ import MatrixClientPeg from '../../MatrixClientPeg';
import MatrixClientBackedSettingsHandler from "./MatrixClientBackedSettingsHandler"; import MatrixClientBackedSettingsHandler from "./MatrixClientBackedSettingsHandler";
import {SettingLevel} from "../SettingsStore"; import {SettingLevel} from "../SettingsStore";
const ALLOWED_WIDGETS_EVENT_TYPE = "im.vector.setting.allowed_widgets";
/** /**
* Gets and sets settings at the "room-account" level for the current user. * Gets and sets settings at the "room-account" level for the current user.
*/ */
@ -58,6 +60,8 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
const val = event.getContent()[settingName]; const val = event.getContent()[settingName];
this._watchers.notifyUpdate(settingName, roomId, SettingLevel.ROOM_ACCOUNT, val); this._watchers.notifyUpdate(settingName, roomId, SettingLevel.ROOM_ACCOUNT, val);
} }
} else if (event.getType() === ALLOWED_WIDGETS_EVENT_TYPE) {
this._watchers.notifyUpdate("allowedWidgets", roomId, SettingLevel.ROOM_ACCOUNT, event.getContent());
} }
} }
@ -79,6 +83,11 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
return this._getSettings(roomId, "org.matrix.room.color_scheme"); return this._getSettings(roomId, "org.matrix.room.color_scheme");
} }
// Special case allowed widgets
if (settingName === "allowedWidgets") {
return this._getSettings(roomId, ALLOWED_WIDGETS_EVENT_TYPE);
}
const settings = this._getSettings(roomId) || {}; const settings = this._getSettings(roomId) || {};
return settings[settingName]; return settings[settingName];
} }
@ -97,6 +106,11 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
return MatrixClientPeg.get().setRoomAccountData(roomId, "org.matrix.room.color_scheme", newValue); return MatrixClientPeg.get().setRoomAccountData(roomId, "org.matrix.room.color_scheme", newValue);
} }
// Special case allowed widgets
if (settingName === "allowedWidgets") {
return return MatrixClientPeg.get().setRoomAccountData(roomId, ALLOWED_WIDGETS_EVENT_TYPE, newValue);
}
const content = this._getSettings(roomId) || {}; const content = this._getSettings(roomId) || {};
content[settingName] = newValue; content[settingName] = newValue;
return MatrixClientPeg.get().setRoomAccountData(roomId, "im.vector.web.settings", content); return MatrixClientPeg.get().setRoomAccountData(roomId, "im.vector.web.settings", content);