mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Merge pull request #1862 from PR0M3TH3AN/update-user-blocks-fetch-logic-13968385690674238472
Update user block fetch logic
This commit is contained in:
2 files changed
+13
-20
No files matched your search
+10
-17
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user