Cleanup handlers

This commit is contained in:
Kieran 2023-09-15 13:14:12 +01:00
parent ca2c9130aa
commit 1a6df18e8b
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 14 additions and 14 deletions

View File

@ -140,10 +140,10 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> implements System
if (!this.#sockets.has(addr)) { if (!this.#sockets.has(addr)) {
const c = new Connection(addr, options, this.#handleAuth?.bind(this)); const c = new Connection(addr, options, this.#handleAuth?.bind(this));
this.#sockets.set(addr, c); this.#sockets.set(addr, c);
c.OnEvent = (s, e) => this.OnEvent(s, e); c.OnEvent = (s, e) => this.#onEvent(s, e);
c.OnEose = s => this.OnEndOfStoredEvents(c, s); c.OnEose = s => this.#onEndOfStoredEvents(c, s);
c.OnDisconnect = code => this.OnRelayDisconnect(c, code); c.OnDisconnect = code => this.#onRelayDisconnect(c, code);
c.OnConnected = r => this.OnRelayConnected(c, r); c.OnConnected = r => this.#onRelayConnected(c, r);
await c.Connect(); await c.Connect();
} else { } else {
// update settings if already connected // update settings if already connected
@ -154,7 +154,7 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> implements System
} }
} }
OnRelayConnected(c: Connection, wasReconnect: boolean) { #onRelayConnected(c: Connection, wasReconnect: boolean) {
if (wasReconnect) { if (wasReconnect) {
for (const [, q] of this.Queries) { for (const [, q] of this.Queries) {
q.connectionRestored(c); q.connectionRestored(c);
@ -162,22 +162,22 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> implements System
} }
} }
OnRelayDisconnect(c: Connection, code: number) { #onRelayDisconnect(c: Connection, code: number) {
this.#relayMetrics.onDisconnect(c, code); this.#relayMetrics.onDisconnect(c, code);
for (const [, q] of this.Queries) { for (const [, q] of this.Queries) {
q.connectionLost(c.Id); q.connectionLost(c.Id);
} }
} }
OnEndOfStoredEvents(c: Readonly<Connection>, sub: string) { #onEndOfStoredEvents(c: Readonly<Connection>, sub: string) {
for (const [, v] of this.Queries) { for (const [, v] of this.Queries) {
v.eose(sub, c); v.eose(sub, c);
} }
} }
OnEvent(sub: string, ev: TaggedNostrEvent) { #onEvent(sub: string, ev: TaggedNostrEvent) {
for (const [, v] of this.Queries) { for (const [, v] of this.Queries) {
v.onEvent(sub, ev); v.handleEvent(sub, ev);
} }
} }
@ -191,10 +191,10 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> implements System
if (!this.#sockets.has(addr)) { if (!this.#sockets.has(addr)) {
const c = new Connection(addr, { read: true, write: true }, this.#handleAuth?.bind(this), true); const c = new Connection(addr, { read: true, write: true }, this.#handleAuth?.bind(this), true);
this.#sockets.set(addr, c); this.#sockets.set(addr, c);
c.OnEvent = (s, e) => this.OnEvent(s, e); c.OnEvent = (s, e) => this.#onEvent(s, e);
c.OnEose = s => this.OnEndOfStoredEvents(c, s); c.OnEose = s => this.#onEndOfStoredEvents(c, s);
c.OnDisconnect = code => this.OnRelayDisconnect(c, code); c.OnDisconnect = code => this.#onRelayDisconnect(c, code);
c.OnConnected = r => this.OnRelayConnected(c, r); c.OnConnected = r => this.#onRelayConnected(c, r);
await c.Connect(); await c.Connect();
return c; return c;
} }

View File

@ -169,7 +169,7 @@ export class Query implements QueryBase {
return this.#feed; return this.#feed;
} }
onEvent(sub: string, e: TaggedNostrEvent) { handleEvent(sub: string, e: TaggedNostrEvent) {
for (const t of this.#tracing) { for (const t of this.#tracing) {
if (t.id === sub) { if (t.id === sub) {
if (t.filters.some(v => eventMatchesFilter(e, v))) { if (t.filters.some(v => eventMatchesFilter(e, v))) {