From 5c0ff43db0e0a26a2ca054a4bc379bb2e49d171d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 10 Jul 2023 10:40:13 +0100 Subject: [PATCH 1/2] PosthogAnalytics unwatch settings on logout --- src/PosthogAnalytics.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PosthogAnalytics.ts b/src/PosthogAnalytics.ts index 995559b1ee2..dc4e4837819 100644 --- a/src/PosthogAnalytics.ts +++ b/src/PosthogAnalytics.ts @@ -138,6 +138,7 @@ export class PosthogAnalytics { private propertiesForNextEvent: Partial> = {}; private userPropertyCache: UserProperties = {}; private authenticationType: Signup["authenticationType"] = "Other"; + private watchSettingRef?: string; public static get instance(): PosthogAnalytics { if (!this._instance) { @@ -337,6 +338,7 @@ export class PosthogAnalytics { if (this.enabled) { this.posthog.reset(); } + if (this.watchSettingRef) SettingsStore.unwatchSetting(this.watchSettingRef); this.setAnonymity(Anonymity.Disabled); } @@ -400,7 +402,7 @@ export class PosthogAnalytics { // * When the user changes their preferences on this device // Note that for new accounts, pseudonymousAnalyticsOptIn won't be set, so updateAnonymityFromSettings // won't be called (i.e. this.anonymity will be left as the default, until the setting changes) - SettingsStore.watchSetting( + this.watchSettingRef = SettingsStore.watchSetting( "pseudonymousAnalyticsOptIn", null, (originalSettingName, changedInRoomId, atLevel, newValueAtLevel, newValue) => { From 7b54ba6e670ee5cc25b27c1859043f534b33b150 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 10 Jul 2023 10:40:16 +0100 Subject: [PATCH 2/2] Tidy --- src/Lifecycle.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Lifecycle.ts b/src/Lifecycle.ts index 6d1be2240d6..9c4a1cfd33f 100644 --- a/src/Lifecycle.ts +++ b/src/Lifecycle.ts @@ -748,11 +748,12 @@ let _isLoggingOut = false; * Logs the current session out and transitions to the logged-out state */ export function logout(): void { - if (!MatrixClientPeg.get()) return; + const client = MatrixClientPeg.get(); + if (!client) return; PosthogAnalytics.instance.logout(); - if (MatrixClientPeg.get()!.isGuest()) { + if (client.isGuest()) { // logout doesn't work for guest sessions // Also we sometimes want to re-log in a guest session if we abort the login. // defer until next tick because it calls a synchronous dispatch, and we are likely here from a dispatch. @@ -761,7 +762,6 @@ export function logout(): void { } _isLoggingOut = true; - const client = MatrixClientPeg.get()!; PlatformPeg.get()?.destroyPickleKey(client.getSafeUserId(), client.getDeviceId() ?? ""); client.logout(true).then(onLoggedOut, (err) => { // Just throwing an error here is going to be very unhelpful