From 018fd6d5996617463c601e154bab5f170a484255 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 27 Jan 2026 23:59:58 +0000 Subject: [PATCH] refactor: update user block fetch logic to prioritize kind 10000 with d-tag Changes `loadBlocks` to fetch `kind: 10000` with `d=user-blocks` instead of `kind: 30002` for block lists, while keeping the generic `kind: 10000` fetch for mute lists. Updates `applyEvents` to separate block lists (tagged or legacy 30002) from mute lists (untagged 10000) and merge them instead of prioritizing one over the other. Updates tests to reflect the merged behavior. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- js/userBlocks.js | 27 ++++++++++----------------- tests/user-blocks.test.mjs | 6 +++--- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/js/userBlocks.js b/js/userBlocks.js index ed7062e5..07caba3c 100644 --- a/js/userBlocks.js +++ b/js/userBlocks.js @@ -986,26 +986,19 @@ class UserBlockListManager { return; } - // Separate by kind to merge distinct lists (Block vs Mute) - const muteEvents = validEvents.filter((e) => e.kind === 10000); - - // Prioritize tagged mute lists (Bitvid) over plain ones (others) - const taggedMutes = muteEvents - .filter((e) => isTaggedBlockListEvent(e)) - .sort((a, b) => (b?.created_at || 0) - (a?.created_at || 0)); - - const plainMutes = muteEvents - .filter((e) => !isTaggedBlockListEvent(e)) - .sort((a, b) => (b?.created_at || 0) - (a?.created_at || 0)); - - const newestMute = - taggedMutes.length > 0 ? taggedMutes[0] : plainMutes[0] || null; - + // Separate by logic (Block vs Mute) + // Block: Kind 10000 with d=user-blocks OR Kind 30002 (legacy) const blockEvents = validEvents - .filter((e) => e.kind === 30002) + .filter((e) => isTaggedBlockListEvent(e) || e.kind === 30002) + .sort((a, b) => (b?.created_at || 0) - (a?.created_at || 0)); + + // Mute: Kind 10000 WITHOUT d=user-blocks + const muteEvents = validEvents + .filter((e) => e.kind === 10000 && !isTaggedBlockListEvent(e)) .sort((a, b) => (b?.created_at || 0) - (a?.created_at || 0)); const newestBlock = blockEvents[0] || null; + const newestMute = muteEvents[0] || null; const newestMuteTime = Number.isFinite(newestMute?.created_at) ? newestMute.created_at @@ -1174,7 +1167,7 @@ class UserBlockListManager { timeoutMs: 12000, }), nostrClient.fetchListIncrementally({ - kind: 30002, + kind: 10000, pubkey: normalized, dTag: BLOCK_LIST_IDENTIFIER, relayUrls: relays, diff --git a/tests/user-blocks.test.mjs b/tests/user-blocks.test.mjs index 67d4fbcf..3fde4000 100644 --- a/tests/user-blocks.test.mjs +++ b/tests/user-blocks.test.mjs @@ -99,7 +99,7 @@ await (async () => { assert.deepEqual( calls, [...relays, ...relays], - "loadBlocks should initiate queries for all relays concurrently (twice, for separate kinds)" + "loadBlocks should initiate queries for all relays concurrently (twice, for block list and mute list)" ); // Reverting to original test data: @@ -1219,7 +1219,7 @@ await (async () => { })(); await (async () => { - // Test: Prioritize 'd=user-blocks' tagged lists over newer plain lists + // Test: Merge 'd=user-blocks' tagged lists with plain lists const actor = "a".repeat(64); const taggedBlocked = "b".repeat(64); const plainBlocked = "c".repeat(64); @@ -1273,7 +1273,7 @@ await (async () => { const blocked = userBlocks.getBlockedPubkeys(); assert.ok(blocked.includes(taggedBlocked), "Should include pubkey from tagged list"); - assert.ok(!blocked.includes(plainBlocked), "Should NOT include pubkey from plain list (fallback ignored)"); + assert.ok(blocked.includes(plainBlocked), "Should include pubkey from plain list (merged)"); } finally { relayManager.setEntries(originalRelayEntries, { allowEmpty: false, updateClient: false }); nostrClient.relays = originalRelays;