From b70d263eff94a55e89f1fe1b7d48d7ce33a5a3f3 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Thu, 22 Jan 2026 21:37:25 -0500 Subject: [PATCH] Update share menu auth handling --- js/app.js | 27 ++++++++++++++++++++++ js/ui/components/VideoModal.js | 31 +++++++++++++++++++++++--- js/ui/components/videoMenuRenderers.js | 9 +++++--- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/js/app.js b/js/app.js index 5c30bf6f..d3960fa9 100644 --- a/js/app.js +++ b/js/app.js @@ -77,6 +77,10 @@ import { publishEventToRelays, assertAnyRelayAccepted, } from "./nostrPublish.js"; +import { + getActiveSigner, + onActiveSignerChanged, +} from "./nostrClientRegistry.js"; import { initViewCounter, subscribeToVideoViewCount, @@ -311,6 +315,12 @@ class Application { this.initializeModerationActionController(); this.initializeSimilarContentController(); + + this.handleShareNostrSignerChange = () => { + this.updateShareNostrAuthState({ reason: "signer-change" }); + }; + onActiveSignerChanged(this.handleShareNostrSignerChange); + this.updateShareNostrAuthState({ reason: "init" }); } get modalVideo() { @@ -4042,6 +4052,21 @@ class Application { return true; } + updateShareNostrAuthState({ reason = "" } = {}) { + if (!this.videoModal?.setShareNostrAuthState) { + return; + } + + const isLoggedIn = this.isUserLoggedIn(); + const hasSigner = Boolean(getActiveSigner()); + + this.videoModal.setShareNostrAuthState({ + isLoggedIn, + hasSigner, + reason, + }); + } + async updateActiveNwcSettings(partial = {}) { return this.nwcSettingsService.updateActiveNwcSettings(partial); } @@ -4296,6 +4321,7 @@ class Application { this.applyAuthenticatedUiState(); this.commentController?.refreshAuthState?.(); + this.updateShareNostrAuthState({ reason: "auth-login" }); if (typeof this.refreshUnreadDmIndicator === "function") { void this.refreshUnreadDmIndicator({ reason: "auth-login" }); } @@ -4551,6 +4577,7 @@ class Application { } this.applyLoggedOutUiState(); + this.updateShareNostrAuthState({ reason: "auth-logout" }); if (typeof this.refreshUnreadDmIndicator === "function") { void this.refreshUnreadDmIndicator({ reason: "auth-logout" }); } else if (this.appChromeController?.setUnreadDmIndicator) { diff --git a/js/ui/components/VideoModal.js b/js/ui/components/VideoModal.js index 2ceedeac..d4cf8b27 100644 --- a/js/ui/components/VideoModal.js +++ b/js/ui/components/VideoModal.js @@ -244,6 +244,10 @@ export class VideoModal { reason: "", parentCommentId: null, }; + this.shareNostrAuthState = { + isLoggedIn: false, + hasSigner: false, + }; this.commentThreadContext = { videoEventId: "", parentCommentId: null, @@ -2578,9 +2582,8 @@ export class VideoModal { } buildModalShareMenuPanel({ document: doc, close }) { - const isLoggedIn = - this.commentComposerState.reason !== "login-required" && - !this.commentComposerState.disabled; + const isLoggedIn = this.shareNostrAuthState.isLoggedIn; + const hasSigner = this.shareNostrAuthState.hasSigner; const hasMagnet = Boolean( (typeof this.activeVideo?.magnet === "string" && @@ -2596,6 +2599,7 @@ export class VideoModal { document: doc, video: this.activeVideo, isLoggedIn, + hasSigner, hasMagnet, hasCdn, context: "modal", @@ -2671,6 +2675,27 @@ export class VideoModal { } } + setShareNostrAuthState({ isLoggedIn, hasSigner } = {}) { + const nextIsLoggedIn = Boolean(isLoggedIn); + const nextHasSigner = Boolean(hasSigner); + const previous = this.shareNostrAuthState; + + if ( + previous && + previous.isLoggedIn === nextIsLoggedIn && + previous.hasSigner === nextHasSigner + ) { + return; + } + + this.shareNostrAuthState = { + isLoggedIn: nextIsLoggedIn, + hasSigner: nextHasSigner, + }; + + this.refreshModalShareMenuPanel(); + } + buildModalMoreMenuPanel({ document: doc, close }) { const panel = createVideoMoreMenuPanel({ document: doc, diff --git a/js/ui/components/videoMenuRenderers.js b/js/ui/components/videoMenuRenderers.js index e66094ac..17c520a7 100644 --- a/js/ui/components/videoMenuRenderers.js +++ b/js/ui/components/videoMenuRenderers.js @@ -313,6 +313,7 @@ export function createVideoShareMenuPanel({ document: documentRef = null, video = null, isLoggedIn = false, + hasSigner = false, hasMagnet = false, hasCdn = false, designSystem = null, @@ -338,10 +339,13 @@ export function createVideoShareMenuPanel({ action: "share-nostr", dataset: { eventId: metadata.id }, }); - if (!isLoggedIn) { + const canShareOnNostr = Boolean(isLoggedIn) && Boolean(hasSigner); + if (!canShareOnNostr) { nostrBtn.disabled = true; nostrBtn.classList.add("opacity-50", "cursor-not-allowed"); - nostrBtn.title = "Log in to share on Nostr"; + nostrBtn.title = isLoggedIn + ? "Connect a Nostr signer to share" + : "Log in to share on Nostr"; } const magnetBtn = appendMenuAction(doc, list, { @@ -488,4 +492,3 @@ export function createVideoSettingsMenuPanel({ return panel; } -