mirror of https://github.com/vector-im/riot-web
PosthogAnalytics unwatch settings on logout (#11207)
* PosthogAnalytics unwatch settings on logout * Tidypull/28788/head^2
parent
411a63f4a5
commit
ab972ddea9
|
@ -748,11 +748,12 @@ let _isLoggingOut = false;
|
||||||
* Logs the current session out and transitions to the logged-out state
|
* Logs the current session out and transitions to the logged-out state
|
||||||
*/
|
*/
|
||||||
export function logout(): void {
|
export function logout(): void {
|
||||||
if (!MatrixClientPeg.get()) return;
|
const client = MatrixClientPeg.get();
|
||||||
|
if (!client) return;
|
||||||
|
|
||||||
PosthogAnalytics.instance.logout();
|
PosthogAnalytics.instance.logout();
|
||||||
|
|
||||||
if (MatrixClientPeg.get()!.isGuest()) {
|
if (client.isGuest()) {
|
||||||
// logout doesn't work for guest sessions
|
// logout doesn't work for guest sessions
|
||||||
// Also we sometimes want to re-log in a guest session if we abort the login.
|
// 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.
|
// 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;
|
_isLoggingOut = true;
|
||||||
const client = MatrixClientPeg.get()!;
|
|
||||||
PlatformPeg.get()?.destroyPickleKey(client.getSafeUserId(), client.getDeviceId() ?? "");
|
PlatformPeg.get()?.destroyPickleKey(client.getSafeUserId(), client.getDeviceId() ?? "");
|
||||||
client.logout(true).then(onLoggedOut, (err) => {
|
client.logout(true).then(onLoggedOut, (err) => {
|
||||||
// Just throwing an error here is going to be very unhelpful
|
// Just throwing an error here is going to be very unhelpful
|
||||||
|
|
|
@ -138,6 +138,7 @@ export class PosthogAnalytics {
|
||||||
private propertiesForNextEvent: Partial<Record<"$set" | "$set_once", UserProperties>> = {};
|
private propertiesForNextEvent: Partial<Record<"$set" | "$set_once", UserProperties>> = {};
|
||||||
private userPropertyCache: UserProperties = {};
|
private userPropertyCache: UserProperties = {};
|
||||||
private authenticationType: Signup["authenticationType"] = "Other";
|
private authenticationType: Signup["authenticationType"] = "Other";
|
||||||
|
private watchSettingRef?: string;
|
||||||
|
|
||||||
public static get instance(): PosthogAnalytics {
|
public static get instance(): PosthogAnalytics {
|
||||||
if (!this._instance) {
|
if (!this._instance) {
|
||||||
|
@ -337,6 +338,7 @@ export class PosthogAnalytics {
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
this.posthog.reset();
|
this.posthog.reset();
|
||||||
}
|
}
|
||||||
|
if (this.watchSettingRef) SettingsStore.unwatchSetting(this.watchSettingRef);
|
||||||
this.setAnonymity(Anonymity.Disabled);
|
this.setAnonymity(Anonymity.Disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +402,7 @@ export class PosthogAnalytics {
|
||||||
// * When the user changes their preferences on this device
|
// * When the user changes their preferences on this device
|
||||||
// Note that for new accounts, pseudonymousAnalyticsOptIn won't be set, so updateAnonymityFromSettings
|
// 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)
|
// 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",
|
"pseudonymousAnalyticsOptIn",
|
||||||
null,
|
null,
|
||||||
(originalSettingName, changedInRoomId, atLevel, newValueAtLevel, newValue) => {
|
(originalSettingName, changedInRoomId, atLevel, newValueAtLevel, newValue) => {
|
||||||
|
|
Loading…
Reference in New Issue