Use device storage for allowed widgets if account data not supported

With guest accounts, account data is not available, so we use device storage to
hold allowed widgets as a good enough place.

Fixes https://github.com/vector-im/element-web/issues/16145
This commit is contained in:
J. Ryan Stinnett 2021-01-14 17:30:25 +00:00
parent cb66f7493b
commit 658a8dfa99
4 changed files with 31 additions and 3 deletions

View file

@ -467,6 +467,31 @@ export default class SettingsStore {
return LEVEL_HANDLERS[level].isSupported();
}
/**
* Determines the first supported level out of all the levels that can be used for a
* specific setting.
* @param {string} settingName The setting name.
* @return {SettingLevel}
*/
public static firstSupportedLevel(settingName: string): SettingLevel {
// Verify that the setting is actually a setting
const setting = SETTINGS[settingName];
if (!setting) {
throw new Error("Setting '" + settingName + "' does not appear to be a setting.");
}
const levelOrder = (setting.supportedLevelsAreOrdered ? setting.supportedLevels : LEVEL_ORDER);
if (!levelOrder.includes(SettingLevel.DEFAULT)) levelOrder.push(SettingLevel.DEFAULT); // always include default
const handlers = SettingsStore.getHandlers(settingName);
for (const level of levelOrder) {
const handler = handlers[level];
if (!handler) continue;
return level;
}
}
/**
* Debugging function for reading explicit setting values without going through the
* complicated/biased functions in the SettingsStore. This will print information to