From c76f780264162493c34daa1a620fd1f092f13bb3 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Tue, 7 Oct 2025 13:36:17 -0400 Subject: [PATCH] Fix moderator management aliases and validation --- js/ui/profileModalController.js | 85 +++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/js/ui/profileModalController.js b/js/ui/profileModalController.js index 5fd13f10..71eb3788 100644 --- a/js/ui/profileModalController.js +++ b/js/ui/profileModalController.js @@ -390,6 +390,10 @@ export class ProfileModalController { this.profileName = null; this.profileNpub = null; this.switcherList = null; + this.profileModalAvatar = null; + this.profileModalName = null; + this.profileModalNpub = null; + this.profileSwitcherList = null; this.globalProfileAvatar = null; this.closeButton = null; this.logoutButton = null; @@ -415,31 +419,54 @@ export class ProfileModalController { this.relayInput = null; this.addRelayButton = null; this.restoreRelaysButton = null; + this.profileRelayList = null; + this.profileRelayInput = null; + this.profileAddRelayBtn = null; + this.profileRestoreRelaysBtn = null; this.blockList = null; this.blockListEmpty = null; this.blockInput = null; this.addBlockedButton = null; + this.profileBlockedList = null; + this.profileBlockedEmpty = null; + this.profileBlockedInput = null; + this.profileAddBlockedBtn = null; this.walletUriInput = null; this.walletDefaultZapInput = null; this.walletSaveButton = null; this.walletTestButton = null; this.walletDisconnectButton = null; this.walletStatusText = null; + this.profileWalletStatusText = null; this.moderatorSection = null; this.moderatorEmpty = null; this.adminModeratorList = null; this.addModeratorButton = null; this.moderatorInput = null; + this.adminModeratorsSection = null; + this.adminModeratorsEmpty = null; + this.adminAddModeratorButton = null; + this.adminModeratorInput = null; this.whitelistSection = null; this.whitelistEmpty = null; this.whitelistList = null; this.addWhitelistButton = null; this.whitelistInput = null; + this.adminWhitelistSection = null; + this.adminWhitelistEmpty = null; + this.adminWhitelistList = null; + this.adminAddWhitelistButton = null; + this.adminWhitelistInput = null; this.blacklistSection = null; this.blacklistEmpty = null; this.blacklistList = null; this.addBlacklistButton = null; this.blacklistInput = null; + this.adminBlacklistSection = null; + this.adminBlacklistEmpty = null; + this.adminBlacklistList = null; + this.adminAddBlacklistButton = null; + this.adminBlacklistInput = null; this.profileHistoryRenderer = null; this.boundProfileHistoryVisibility = null; @@ -495,6 +522,11 @@ export class ProfileModalController { this.profileNpub = document.getElementById("profileModalNpub") || null; this.switcherList = document.getElementById("profileSwitcherList") || null; + this.profileModalAvatar = this.profileAvatar; + this.profileModalName = this.profileName; + this.profileModalNpub = this.profileNpub; + this.profileSwitcherList = this.switcherList; + const topLevelProfileAvatar = document.getElementById("profileAvatar") || null; if (topLevelProfileAvatar) { @@ -541,6 +573,16 @@ export class ProfileModalController { this.walletStatusText = document.getElementById("profileWalletStatus") || null; + this.profileRelayList = this.relayList; + this.profileRelayInput = this.relayInput; + this.profileAddRelayBtn = this.addRelayButton; + this.profileRestoreRelaysBtn = this.restoreRelaysButton; + this.profileBlockedList = this.blockList; + this.profileBlockedEmpty = this.blockListEmpty; + this.profileBlockedInput = this.blockInput; + this.profileAddBlockedBtn = this.addBlockedButton; + this.profileWalletStatusText = this.walletStatusText; + this.moderatorSection = document.getElementById("adminModeratorsSection") || null; this.moderatorEmpty = @@ -551,6 +593,14 @@ export class ProfileModalController { document.getElementById("adminAddModeratorBtn") || null; this.moderatorInput = document.getElementById("adminModeratorInput") || null; + + // Backwards-compatible aliases retained for application code that still + // mirrors DOM references from the controller. These should be removed once + // the application stops reaching through the controller. + this.adminModeratorsSection = this.moderatorSection; + this.adminModeratorsEmpty = this.moderatorEmpty; + this.adminAddModeratorButton = this.addModeratorButton; + this.adminModeratorInput = this.moderatorInput; this.whitelistSection = document.getElementById("adminWhitelistSection") || null; this.whitelistEmpty = @@ -572,6 +622,17 @@ export class ProfileModalController { this.blacklistInput = document.getElementById("adminBlacklistInput") || null; + this.adminWhitelistSection = this.whitelistSection; + this.adminWhitelistEmpty = this.whitelistEmpty; + this.adminWhitelistList = this.whitelistList; + this.adminAddWhitelistButton = this.addWhitelistButton; + this.adminWhitelistInput = this.whitelistInput; + this.adminBlacklistSection = this.blacklistSection; + this.adminBlacklistEmpty = this.blacklistEmpty; + this.adminBlacklistList = this.blacklistList; + this.adminAddBlacklistButton = this.addBlacklistButton; + this.adminBlacklistInput = this.blacklistInput; + if (!this.profileHistoryRenderer && this.createWatchHistoryRenderer) { this.profileHistoryRenderer = this.createWatchHistoryRenderer({ viewSelector: "#profilePaneHistory", @@ -2296,7 +2357,7 @@ export class ProfileModalController { this.renderAdminList( this.adminModeratorList, - this.adminModeratorsEmpty, + this.moderatorEmpty, editors, { onRemove: (npub, button) => this.handleRemoveModerator(npub, button), @@ -2448,10 +2509,12 @@ export class ProfileModalController { const input = this.moderatorInput || null; const rawValue = typeof input?.value === "string" ? input.value : ""; const trimmed = rawValue.trim(); + const normalizedValue = this.normalizeNpubValue(trimmed); const context = { input, rawValue, value: trimmed, + normalizedValue, actorNpub: null, success: false, reason: null, @@ -2493,6 +2556,13 @@ export class ProfileModalController { return context; } + if (!normalizedValue) { + this.showError("Enter a valid npub before adding it as a moderator."); + context.reason = "invalid"; + this.callbacks.onAdminAddModerator(context, this); + return context; + } + if (this.addModeratorButton) { this.addModeratorButton.disabled = true; this.addModeratorButton.setAttribute("aria-busy", "true"); @@ -2502,7 +2572,7 @@ export class ProfileModalController { const mutationResult = await this.runAdminMutation({ action: "add-moderator", actorNpub, - targetNpub: trimmed, + targetNpub: normalizedValue, }); context.result = mutationResult?.result || null; if (!mutationResult?.ok) { @@ -2532,6 +2602,7 @@ export class ProfileModalController { async handleRemoveModerator(npub, button) { const context = { npub, + normalizedNpub: this.normalizeNpubValue(npub), button, actorNpub: null, success: false, @@ -2547,6 +2618,14 @@ export class ProfileModalController { } }; + if (!context.normalizedNpub) { + this.showError("Unable to remove moderator: invalid npub."); + context.reason = "invalid"; + releaseButton(); + this.callbacks.onAdminRemoveModerator(context, this); + return context; + } + let preloadError = null; try { const ensureResult = await this.runAdminMutation({ action: "ensure-ready" }); @@ -2579,7 +2658,7 @@ export class ProfileModalController { const mutationResult = await this.runAdminMutation({ action: "remove-moderator", actorNpub, - targetNpub: npub, + targetNpub: context.normalizedNpub, }); context.result = mutationResult?.result || null; if (!mutationResult?.ok) {