mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Update user block relay selection
This commit is contained in:
1 parent
5cac280c3d
commit
e0bb0edf7a
1 file changed
+30
-5
+30
-5
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user