Update user block relay selection

This commit is contained in:
thePR0M3TH3AN committed 2026-01-27 16:54:37 -05:00
1 parent 5cac280c3d
commit e0bb0edf7a
1 file changed
+30 -5
+30 -5
View File
@@ -18,6 +18,7 @@ import {
assertAnyRelayAccepted,
} from "./nostrPublish.js";
import { profileCache } from "./state/profileCache.js";
import { DEFAULT_RELAY_URLS } from "./nostr/toolkit.js";
class TinyEventEmitter {
constructor() {
@@ -72,6 +73,14 @@ const FAST_BLOCKLIST_RELAY_LIMIT = 3;
const FAST_BLOCKLIST_TIMEOUT_MS = 2500;
const BACKGROUND_BLOCKLIST_TIMEOUT_MS = 6000;
function sanitizeRelayList(candidate) {
return Array.isArray(candidate)
? candidate
.map((url) => (typeof url === "string" ? url.trim() : ""))
.filter(Boolean)
: [];
}
function normalizeEncryptionToken(value) {
if (typeof value !== "string") {
return "";
@@ -726,7 +735,27 @@ class UserBlockListManager {
}
};
emitStatus({ status: "loading", relays: Array.from(nostrClient.relays || []) });
const relaySet = new Set();
const addRelays = (candidate) => {
const sanitized = sanitizeRelayList(candidate);
for (const relay of sanitized) {
relaySet.add(relay);
}
};
addRelays(nostrClient.relays);
if (!relaySet.size) {
addRelays(nostrClient.readRelays);
}
if (!relaySet.size) {
addRelays(nostrClient.writeRelays);
}
if (!relaySet.size) {
addRelays(DEFAULT_RELAY_URLS);
}
const relays = Array.from(relaySet);
emitStatus({ status: "loading", relays });
const localBlocks = this._loadLocal(normalized);
const hasLocalData = !!localBlocks;
@@ -872,10 +901,6 @@ class UserBlockListManager {
};
try {
const relays = Array.isArray(nostrClient.relays)
? nostrClient.relays.filter((relay) => typeof relay === "string" && relay)
: [];
if (!relays.length) {
// Only clear if truly no relays, though loadBlocks with no relays is weird.
if (!this.loaded) {