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

Commit

Permalink
Keep device language when it has been previosuly set, after a success…
Browse files Browse the repository at this point in the history
…ful delegated authentication flow that clears localStorage (#11902)

* Do not remove the language when clearing local storage

Signed-off-by: Milton Moura <miltonmoura@gmail.com>

* Revised comment on getting the defined language from settings

Signed-off-by: Milton Moura <miltonmoura@gmail.com>

* Explicitly checking for language set at the device level

Signed-off-by: Milton Moura <miltonmoura@gmail.com>

* Add test that checks if device language setting is kept after a successfull delegated authentication flow

Signed-off-by: Milton Moura <miltonmoura@gmail.com>

* Adds test for unhappy path and adjusts to use the SettingsStore instead of going directly to localStorage

Signed-off-by: Milton Moura <miltonmoura@gmail.com>

* Removing unnecessary variable after test refactor

Signed-off-by: Milton Moura <miltonmoura@gmail.com>

---------

Signed-off-by: Milton Moura <miltonmoura@gmail.com>
  • Loading branch information
mgcm committed Nov 24, 2023
1 parent ba3395e commit 76b7aa2
Show file tree
Hide file tree
Showing 2 changed files with 291 additions and 253 deletions.
10 changes: 9 additions & 1 deletion src/Lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import PlatformPeg from "./PlatformPeg";
import { sendLoginRequest } from "./Login";
import * as StorageManager from "./utils/StorageManager";
import SettingsStore from "./settings/SettingsStore";
import { SettingLevel } from "./settings/SettingLevel";
import ToastStore from "./stores/ToastStore";
import { IntegrationManagers } from "./integrations/IntegrationManagers";
import { Mjolnir } from "./mjolnir/Mjolnir";
Expand Down Expand Up @@ -1105,6 +1106,9 @@ export async function onLoggedOut(): Promise<void> {
*/
async function clearStorage(opts?: { deleteEverything?: boolean }): Promise<void> {
if (window.localStorage) {
// get the currently defined device language, if set, so we can restore it later
const language = SettingsStore.getValueAt(SettingLevel.DEVICE, "language", null, true, true);

// try to save any 3pid invites from being obliterated and registration time
const pendingInvites = ThreepidInviteStore.instance.getWireInvites();
const registrationTime = window.localStorage.getItem("mx_registration_time");
Expand All @@ -1118,8 +1122,12 @@ async function clearStorage(opts?: { deleteEverything?: boolean }): Promise<void
logger.error("idbDelete failed for account:mx_access_token", e);
}

// now restore those invites and registration time
// now restore those invites, registration time and previously set device language
if (!opts?.deleteEverything) {
if (language) {
await SettingsStore.setValue("language", null, SettingLevel.DEVICE, language);
}

pendingInvites.forEach(({ roomId, ...invite }) => {
ThreepidInviteStore.instance.storeInvite(roomId, invite);
});
Expand Down
Loading

0 comments on commit 76b7aa2

Please sign in to comment.