From ad3375ed0983c0f30c839a325424923f4512b2a3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 23 Jan 2026 04:39:18 +0000 Subject: [PATCH] fix: ensure access control lists are loaded before playback Introduced `waitForReady` in `AccessControl` to block until moderation lists are fetched, and updated `playVideoByEventId` and `trustBootstrap` to use it, preventing false "not whitelisted" errors in private tabs. --- js/accessControl.js | 7 +++++++ js/app.js | 4 ++-- js/services/nostrService.js | 4 ++-- js/services/trustBootstrap.js | 6 +++--- tests/moderation/trust-seeds.test.mjs | 3 +++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/js/accessControl.js b/js/accessControl.js index 3f9d7cd9..e21fb429 100644 --- a/js/accessControl.js +++ b/js/accessControl.js @@ -449,6 +449,13 @@ class AccessControl { return Promise.resolve(); } + async waitForReady() { + if (this.hasLoaded) { + return; + } + return this.refresh(); + } + whitelistMode() { return this.whitelistEnabled; } diff --git a/js/app.js b/js/app.js index e81b47d7..00aa74e8 100644 --- a/js/app.js +++ b/js/app.js @@ -3776,7 +3776,7 @@ class Application { try { switch (action) { case "ensure-ready": - await accessControl.ensureReady(); + await accessControl.waitForReady(); context.ok = true; break; case "add-moderator": @@ -8286,7 +8286,7 @@ class Application { } try { - await accessControl.ensureReady(); + await accessControl.waitForReady(); } catch (error) { devLogger.warn( "Failed to ensure admin lists were loaded before playback:", diff --git a/js/services/nostrService.js b/js/services/nostrService.js index f1f1f3e0..20c32a9f 100644 --- a/js/services/nostrService.js +++ b/js/services/nostrService.js @@ -1402,12 +1402,12 @@ export class NostrService { } async ensureAccessControlReady() { - if (!this.accessControl || typeof this.accessControl.ensureReady !== "function") { + if (!this.accessControl || typeof this.accessControl.waitForReady !== "function") { return; } try { - await this.accessControl.ensureReady(); + await this.accessControl.waitForReady(); } catch (error) { userLogger.warn( "[nostrService] Failed to ensure access control lists are ready:", diff --git a/js/services/trustBootstrap.js b/js/services/trustBootstrap.js index 4f029bb5..e6f262c9 100644 --- a/js/services/trustBootstrap.js +++ b/js/services/trustBootstrap.js @@ -64,7 +64,7 @@ async function waitForRelaysReady({ timeoutMs = TRUST_SEED_READY_TIMEOUT_MS } = } async function waitForAccessControl({ timeoutMs = TRUST_SEED_READY_TIMEOUT_MS } = {}) { - if (!accessControl || typeof accessControl.ensureReady !== "function") { + if (!accessControl || typeof accessControl.waitForReady !== "function") { return { ok: true, timedOut: false }; } @@ -72,12 +72,12 @@ async function waitForAccessControl({ timeoutMs = TRUST_SEED_READY_TIMEOUT_MS } const timeoutPromise = new Promise((_, reject) => { setTimeout(() => { timedOut = true; - reject(new Error("accessControl ensureReady timed out")); + reject(new Error("accessControl ready check timed out")); }, timeoutMs); }); try { - await Promise.race([accessControl.ensureReady(), timeoutPromise]); + await Promise.race([accessControl.waitForReady(), timeoutPromise]); return { ok: true, timedOut: false }; } catch (error) { if (timedOut) { diff --git a/tests/moderation/trust-seeds.test.mjs b/tests/moderation/trust-seeds.test.mjs index a68cf045..01e970a5 100644 --- a/tests/moderation/trust-seeds.test.mjs +++ b/tests/moderation/trust-seeds.test.mjs @@ -158,6 +158,9 @@ test("bootstrap seeds track editor roster and ignore whitelist-only changes", as ensureReady: async () => { ensureReadyCalls += 1; }, + waitForReady: async () => { + ensureReadyCalls += 1; + }, getEditors: () => { getEditorsCalls += 1; return currentEditors;