Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix temporary sync errors if there's weird settings stored in account data #8857

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/settings/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ export default class SettingsStore {
const watcherId = `${new Date().getTime()}_${SettingsStore.watcherCount++}_${settingName}_${roomId}`;

const localizedCallback = (changedInRoomId: string | null, atLevel: SettingLevel, newValAtLevel: any) => {
if (!SettingsStore.doesSettingSupportLevel(originalSettingName, atLevel)) {
logger.warn(
`Setting handler notified for an update of an invalid setting level: ` +
`${originalSettingName}@${atLevel} - this likely means a weird setting value ` +
`made it into the level's storage. The notification will be ignored.`,
);
return;
}
const newValue = SettingsStore.getValue(originalSettingName);
const newValueAtLevel = SettingsStore.getValueAt(atLevel, originalSettingName) ?? newValAtLevel;
callbackFn(originalSettingName, changedInRoomId, atLevel, newValueAtLevel, newValue);
Expand Down Expand Up @@ -516,6 +524,23 @@ export default class SettingsStore {
return LEVEL_HANDLERS[level].isSupported();
}

/**
* Determines if a setting supports a particular level.
* @param settingName The setting name.
* @param level The level.
* @returns True if supported, false otherwise. Note that this will not check to see if
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
* the level itself can be supported by the runtime (ie: you will need to call #isLevelSupported()
* on your own).
*/
public static doesSettingSupportLevel(settingName: string, level: SettingLevel): boolean {
const setting = SETTINGS[settingName];
if (!setting) {
throw new Error("Setting '" + settingName + "' does not appear to be a setting.");
}

return level === SettingLevel.DEFAULT || (setting.supportedLevels.includes(level));
}

/**
* Determines the first supported level out of all the levels that can be used for a
* specific setting.
Expand Down