Migrate the hidden read receipts flag to new "send read receipts" option (#9141)

* Migrate the hidden read receipts flag to new "send read receipts" option

For safety.

* Appease linter & ignore guests

* `void`
This commit is contained in:
Travis Ralston 2022-08-08 15:48:28 -04:00 committed by GitHub
parent f467d94603
commit 32478db57e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 153 additions and 6 deletions

View file

@ -35,6 +35,9 @@ import SettingsHandler from "./handlers/SettingsHandler";
import { SettingUpdatedPayload } from "../dispatcher/payloads/SettingUpdatedPayload";
import { Action } from "../dispatcher/actions";
import PlatformSettingsHandler from "./handlers/PlatformSettingsHandler";
import dispatcher from "../dispatcher/dispatcher";
import { ActionPayload } from "../dispatcher/payloads";
import { MatrixClientPeg } from "../MatrixClientPeg";
const defaultWatchManager = new WatchManager();
@ -565,6 +568,44 @@ export default class SettingsStore {
return null;
}
/**
* Runs or queues any setting migrations needed.
*/
public static runMigrations(): void {
// Dev notes: to add your migration, just add a new `migrateMyFeature` function, call it, and
// add a comment to note when it can be removed.
SettingsStore.migrateHiddenReadReceipts(); // Can be removed after October 2022.
}
private static migrateHiddenReadReceipts(): void {
if (MatrixClientPeg.get().isGuest()) return; // not worth it
// We wait for the first sync to ensure that the user's existing account data has loaded, as otherwise
// getValue() for an account-level setting like sendReadReceipts will return `null`.
const disRef = dispatcher.register((payload: ActionPayload) => {
if (payload.action === "MatrixActions.sync") {
dispatcher.unregister(disRef);
const rrVal = SettingsStore.getValue("sendReadReceipts", null, true);
if (typeof rrVal !== "boolean") {
// new setting isn't set - see if the labs flag was. We have to manually reach into the
// handler for this because it isn't a setting anymore (`getValue` will yell at us).
const handler = LEVEL_HANDLERS[SettingLevel.DEVICE] as DeviceSettingsHandler;
const labsVal = handler.readFeature("feature_hidden_read_receipts");
if (typeof labsVal === "boolean") {
// Inverse of labs flag because negative->positive language switch in setting name
const newVal = !labsVal;
console.log(`Setting sendReadReceipts to ${newVal} because of previously-set labs flag`);
// noinspection JSIgnoredPromiseFromCall
SettingsStore.setValue("sendReadReceipts", null, SettingLevel.ACCOUNT, newVal);
}
}
}
});
}
/**
* Debugging function for reading explicit setting values without going through the
* complicated/biased functions in the SettingsStore. This will print information to