From 1642b787ec087ecd0f6de7ecf150bfa96399dbd7 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Thu, 29 Jan 2026 15:54:44 -0500 Subject: [PATCH] Reset caches on logout --- js/app.js | 16 ++++++++++++++++ js/services/authService.js | 8 ++++++++ js/services/dmNotificationManager.js | 5 +++++ js/services/nostrService.js | 7 +++++++ js/state/profileCache.js | 8 ++++++++ 5 files changed, 44 insertions(+) diff --git a/js/app.js b/js/app.js index 29816a9f..e696dccc 100644 --- a/js/app.js +++ b/js/app.js @@ -4706,6 +4706,22 @@ class Application { } } + if (typeof this.nostrService?.stopDirectMessageSubscription === "function") { + try { + this.nostrService.stopDirectMessageSubscription(); + } catch (error) { + devLogger.warn("Failed to stop DM subscription during logout:", error); + } + } + + if (typeof this.nostrService?.clearDirectMessages === "function") { + try { + this.nostrService.clearDirectMessages({ emit: true }); + } catch (error) { + devLogger.warn("Failed to clear cached DMs during logout:", error); + } + } + if (typeof this.nostrService?.clearVideoSubscription === "function") { try { this.nostrService.clearVideoSubscription(); diff --git a/js/services/authService.js b/js/services/authService.js index df45f56d..129e78f1 100644 --- a/js/services/authService.js +++ b/js/services/authService.js @@ -836,6 +836,14 @@ export default class AuthService { setCurrentUserNpub(null); setActiveProfilePubkey(null, { persist: true }); + try { + if (profileCache && typeof profileCache.reset === "function") { + profileCache.reset(); + } + } catch (error) { + this.log("[AuthService] profileCache.reset threw", error); + } + try { resetModerationSettings({ persist: true }); } catch (error) { diff --git a/js/services/dmNotificationManager.js b/js/services/dmNotificationManager.js index 5670071d..0e45ed83 100644 --- a/js/services/dmNotificationManager.js +++ b/js/services/dmNotificationManager.js @@ -46,6 +46,11 @@ export class DmNotificationManager { return this.focusedConversationId; } + reset() { + this.conversationCache.clear(); + this.focusedConversationId = ""; + } + setFocusedConversation(conversationId, isFocused = true) { if (typeof conversationId !== "string") { return; diff --git a/js/services/nostrService.js b/js/services/nostrService.js index 40bbec66..01316bf1 100644 --- a/js/services/nostrService.js +++ b/js/services/nostrService.js @@ -754,6 +754,13 @@ export class NostrService { if (this.dmPreviewCache) { this.dmPreviewCache.clear(); } + if (this.dmNotificationManager?.reset) { + try { + this.dmNotificationManager.reset(); + } catch (error) { + userLogger.warn("[nostrService] Failed to reset DM notifications cache", error); + } + } const activeActor = normalizeHexPubkey( typeof actorPubkey === "string" && actorPubkey ? actorPubkey diff --git a/js/state/profileCache.js b/js/state/profileCache.js index eacf26f4..38115b51 100644 --- a/js/state/profileCache.js +++ b/js/state/profileCache.js @@ -346,6 +346,14 @@ class ProfileCache { this.emit("runtimeCleared", { pubkey: normalized }); } + reset() { + const previousPubkey = this.activePubkey; + this.activePubkey = null; + this.memoryCache.clear(); + this.emit("profileChanged", { pubkey: null, previousPubkey: previousPubkey || null }); + this.emit("reset", { previousPubkey: previousPubkey || null }); + } + subscribe(callback) { this.listeners.add(callback); return () => this.listeners.delete(callback);