From c8582c7199806c0b21bf9103761907bb706f9333 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 24 Mar 2022 16:11:01 -0600 Subject: [PATCH] Step 8.5: Move logout call during deactivation --- src/Lifecycle.ts | 8 ++++++++ src/components/views/dialogs/DeactivateAccountDialog.tsx | 5 +++-- src/dispatcher/actions.ts | 9 +++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Lifecycle.ts b/src/Lifecycle.ts index 340c4fa2ca..645963a8bd 100644 --- a/src/Lifecycle.ts +++ b/src/Lifecycle.ts @@ -60,10 +60,18 @@ import StorageEvictedDialog from "./components/views/dialogs/StorageEvictedDialo import { setSentryUser } from "./sentry"; import SdkConfig from "./SdkConfig"; import { DialogOpener } from "./utils/DialogOpener"; +import { Action } from "./dispatcher/actions"; const HOMESERVER_URL_KEY = "mx_hs_url"; const ID_SERVER_URL_KEY = "mx_is_url"; +dis.register((payload) => { + if (payload.action === Action.TriggerLogout) { + // noinspection JSIgnoredPromiseFromCall - we don't care if it fails + onLoggedOut(); + } +}); + interface ILoadSessionOpts { enableGuest?: boolean; guestHsUrl?: string; diff --git a/src/components/views/dialogs/DeactivateAccountDialog.tsx b/src/components/views/dialogs/DeactivateAccountDialog.tsx index bf2f636d5d..a505d5e647 100644 --- a/src/components/views/dialogs/DeactivateAccountDialog.tsx +++ b/src/components/views/dialogs/DeactivateAccountDialog.tsx @@ -21,12 +21,13 @@ import { logger } from "matrix-js-sdk/src/logger"; import Analytics from '../../../Analytics'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; -import * as Lifecycle from '../../../Lifecycle'; import { _t } from '../../../languageHandler'; import InteractiveAuth, { ERROR_USER_CANCELLED } from "../../structures/InteractiveAuth"; import { DEFAULT_PHASE, PasswordAuthEntry, SSOAuthEntry } from "../auth/InteractiveAuthEntryComponents"; import StyledCheckbox from "../elements/StyledCheckbox"; import BaseDialog from "./BaseDialog"; +import defaultDispatcher from "../../../dispatcher/dispatcher"; +import { Action } from "../../../dispatcher/actions"; interface IProps { onFinished: (success: boolean) => void; @@ -122,7 +123,7 @@ export default class DeactivateAccountDialog extends React.Component { // Deactivation worked - logout & close this dialog Analytics.trackEvent('Account', 'Deactivate Account'); - Lifecycle.onLoggedOut(); + defaultDispatcher.fire(Action.TriggerLogout); this.props.onFinished(true); }).catch(e => { logger.error(e); diff --git a/src/dispatcher/actions.ts b/src/dispatcher/actions.ts index 5662da1de5..adfbc874a4 100644 --- a/src/dispatcher/actions.ts +++ b/src/dispatcher/actions.ts @@ -283,4 +283,13 @@ export enum Action { * Payload: OpenTabbedIntegrationManagerDialogPayload */ OpenTabbedIntegrationManagerDialog = "open_tabbed_imanager_dialog", + + /** + * Fired when something within the application has determined that a logout, + * or logout-like behaviour, needs to happen. Specifically meant to target + * storage deletion rather than calling the logout API. + * + * No payload. + */ + TriggerLogout = "trigger_logout", }