feat: UserState

This commit is contained in:
2024-04-22 14:38:14 +01:00
parent 5a7657a95d
commit 80a4b5d8e6
103 changed files with 4179 additions and 1165 deletions

View File

@ -99,11 +99,11 @@ export interface TraceReport {
}
export interface QueryEvents {
loading: (v: boolean) => void;
trace: (report: TraceReport) => void;
request: (subId: string, req: BuiltRawReqFilter) => void;
event: (evs: Array<TaggedNostrEvent>) => void;
end: () => void;
done: () => void;
}
const QueryCache = new LRUCache<string, Array<TaggedNostrEvent>>({
@ -357,7 +357,7 @@ export class Query extends EventEmitter<QueryEvents> {
const isFinished = this.progress === 1;
if (isFinished) {
this.#log("%s loading=%s, progress=%d, traces=%O", this.id, !isFinished, this.progress, this.#tracing);
this.emit("loading", !isFinished);
this.emit("done");
}
}
@ -384,6 +384,10 @@ export class Query extends EventEmitter<QueryEvents> {
if (q.relay && q.relay !== c.Address) {
return false;
}
// connection is down, dont send
if (c.isDown) {
return false;
}
// cannot send unless relay is tagged on ephemeral relay connection
if (!q.relay && c.Ephemeral) {
this.#log("Cant send non-specific REQ to ephemeral connection %O %O %O", q, q.relay, c);