PR changes

This commit is contained in:
2023-01-28 15:40:19 +00:00
parent fd770f798d
commit 56e8e85f74
9 changed files with 77 additions and 39 deletions

View File

@ -7,6 +7,7 @@ import { DefaultConnectTimeout } from "Const";
import { ConnectionStats } from "Nostr/ConnectionStats";
import { RawEvent, TaggedRawEvent, u256 } from "Nostr";
import { RelayInfo } from "./RelayInfo";
import Nips from "./Nips";
export type CustomHook = (state: Readonly<StateSnapshot>) => void;
@ -238,6 +239,11 @@ export default class Connection {
return;
}
// check relay supports search
if (sub.Search && !this.SupportsNip(Nips.Search)) {
return;
}
if (this.Subscriptions.has(sub.Id)) {
return;
}
@ -281,6 +287,13 @@ export default class Connection {
return this.LastState;
}
/**
* Using relay document to determine if this relay supports a feature
*/
SupportsNip(n: number) {
return this.Info?.supported_nips?.some(a => a === n) ?? false;
}
_UpdateState() {
this.CurrentState.connected = this.Socket?.readyState === WebSocket.OPEN;
this.CurrentState.events.received = this.Stats.EventsReceived;