mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-09-28 20:43:33 +02:00
small fix for nostr-connect
This commit is contained in:
@@ -6,6 +6,7 @@ import { isFilterEqual } from "../helpers/nostr/filter";
|
|||||||
import ControlledObservable from "./controlled-observable";
|
import ControlledObservable from "./controlled-observable";
|
||||||
import { Filter, Relay, Subscription } from "nostr-tools";
|
import { Filter, Relay, Subscription } from "nostr-tools";
|
||||||
import { offlineMode } from "../services/offline-mode";
|
import { offlineMode } from "../services/offline-mode";
|
||||||
|
import RelaySet from "./relay-set";
|
||||||
|
|
||||||
export default class NostrMultiSubscription {
|
export default class NostrMultiSubscription {
|
||||||
static INIT = "initial";
|
static INIT = "initial";
|
||||||
@@ -64,9 +65,9 @@ export default class NostrMultiSubscription {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlArr = Array.from(relays);
|
const relaySet = RelaySet.from(relays);
|
||||||
for (const relay of this.relays) {
|
for (const relay of this.relays) {
|
||||||
if (!urlArr.includes(relay.url)) {
|
if (!relaySet.has(relay.url)) {
|
||||||
this.relays = this.relays.filter((r) => r !== relay);
|
this.relays = this.relays.filter((r) => r !== relay);
|
||||||
this.handleRemoveRelay(relay);
|
this.handleRemoveRelay(relay);
|
||||||
}
|
}
|
||||||
@@ -111,7 +112,7 @@ export default class NostrMultiSubscription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
publish(event: NostrEvent) {
|
publish(event: NostrEvent) {
|
||||||
return Promise.all(this.relays.map((r) => r.publish(event)));
|
return Promise.allSettled(this.relays.map((r) => r.publish(event)));
|
||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
@@ -127,7 +128,7 @@ export default class NostrMultiSubscription {
|
|||||||
}
|
}
|
||||||
waitForAllConnection(): Promise<void> {
|
waitForAllConnection(): Promise<void> {
|
||||||
if (offlineMode.value) return Promise.resolve();
|
if (offlineMode.value) return Promise.resolve();
|
||||||
return Promise.all(this.relays.filter((r) => !r.connected).map((r) => r.connect())).then((v) => void 0);
|
return Promise.allSettled(this.relays.filter((r) => !r.connected).map((r) => r.connect())).then((v) => void 0);
|
||||||
}
|
}
|
||||||
close() {
|
close() {
|
||||||
if (this.state !== NostrMultiSubscription.OPEN) return this;
|
if (this.state !== NostrMultiSubscription.OPEN) return this;
|
||||||
|
@@ -75,7 +75,7 @@ export class NostrConnectClient {
|
|||||||
supportedMethods: NostrConnectMethod[] | undefined;
|
supportedMethods: NostrConnectMethod[] | undefined;
|
||||||
|
|
||||||
constructor(pubkey: string, relays: string[], secretKey?: string, provider?: string) {
|
constructor(pubkey: string, relays: string[], secretKey?: string, provider?: string) {
|
||||||
this.sub = new NostrMultiSubscription(`${truncatedId(pubkey)}-nostr-connect`);
|
this.sub = new NostrMultiSubscription(`${pubkey}-nostr-connect`);
|
||||||
this.pubkey = pubkey;
|
this.pubkey = pubkey;
|
||||||
this.relays = relays;
|
this.relays = relays;
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
|
Reference in New Issue
Block a user