Skip to content

Commit 533ad02

Browse files
authored
fix: call logout request on logout (stoatchat#1197)
Signed-off-by: Jacob Schlecht <dadadah@echoha.us>
1 parent 9de7488 commit 533ad02

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

packages/client/components/client/Controller.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ class Lifecycle {
121121

122122
private dispose() {
123123
if (this.client) {
124-
this.client.events.removeAllListeners();
125-
this.client.removeAllListeners();
126-
this.client.events.disconnect();
124+
this.client.logout();
127125
}
128126

129127
this.client = new Client({
@@ -599,7 +597,7 @@ export default class ClientController {
599597

600598
logout() {
601599
this.state.settings.resetNotificationsState();
602-
killServiceWorkerSubscription(this.getCurrentClient());
600+
killServiceWorkerSubscription(this.getCurrentClient(), true);
603601
this.state.auth.removeSession();
604602
this.lifecycle.transition({
605603
type: TransitionType.Logout,

packages/client/components/client/NotificationsController.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ function arrayBufferToBase64URL(buffer: ArrayBuffer): string {
173173
}
174174

175175
/** Exported for the client controller. Don't use this unless you have to. */
176-
export async function killServiceWorkerSubscription(client: Client) {
176+
export async function killServiceWorkerSubscription(
177+
client: Client,
178+
loggingOut?: boolean,
179+
) {
177180
if (IS_DEV) {
178181
console.log("Skipping killing push worker in dev.");
179182
return;
@@ -183,6 +186,6 @@ export async function killServiceWorkerSubscription(client: Client) {
183186
if (!registration) return;
184187
const subscription = await registration.pushManager.getSubscription();
185188
if (await subscription?.unsubscribe()) {
186-
await client.api.post("/push/unsubscribe");
189+
if (!loggingOut) await client.api.post("/push/unsubscribe");
187190
}
188191
}

0 commit comments

Comments
 (0)