mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Update share menu auth handling
This commit is contained in:
1 parent
4c55e56955
commit
b70d263eff
3 files changed
+61
-6
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user