From 651eab9e2b9156bbfb368e9f04b55e9a976b3040 Mon Sep 17 00:00:00 2001
From: Sandwich <299465+dskvr@users.noreply.github.com>
Date: Tue, 14 Jan 2025 16:14:53 +0700
Subject: [PATCH] fix operator feed regression
---
.../components/lists/table/DataTable.svelte | 2 --
.../gui/src/lib/services/UserService/index.ts | 27 ++++++++-----------
libraries/nip66/src/core/WebsocketAdapter.ts | 22 ++++-----------
libraries/nip66/src/services/Service.ts | 20 +++++++++++---
libraries/nocap/src/classes/Base.ts | 1 -
5 files changed, 32 insertions(+), 40 deletions(-)
diff --git a/apps/gui/src/lib/components/lists/table/DataTable.svelte b/apps/gui/src/lib/components/lists/table/DataTable.svelte
index dc10deb5..c1fb4a2c 100644
--- a/apps/gui/src/lib/components/lists/table/DataTable.svelte
+++ b/apps/gui/src/lib/components/lists/table/DataTable.svelte
@@ -206,8 +206,6 @@
-
{JSON.stringify(Object.keys($config.tableFormatters).length, null, 2)}
-
diff --git a/apps/gui/src/lib/services/UserService/index.ts b/apps/gui/src/lib/services/UserService/index.ts
index 93731eb9..1b8a8955 100644
--- a/apps/gui/src/lib/services/UserService/index.ts
+++ b/apps/gui/src/lib/services/UserService/index.ts
@@ -40,6 +40,7 @@ export class UserService extends Service {
super(adapters)
this.addRelay('userMeta', 'wss://purplepag.es')
this.addRelay('userMeta', 'wss://user.kindpag.es')
+ this._ready = true;
}
get subIds(): string[] {
@@ -73,26 +74,20 @@ export class UserService extends Service {
return notes;
}
- async unsubscribe(hash?: string): Promise {
- const $nip66: Nip66 = get(nip66)
- await $nip66.adapters?.websocket?.unsubscribe(hash)
- }
+ // async unsubscribe(hash?: string): Promise {
+ // const $nip66: Nip66 = get(nip66)
+ // await $nip66.adapters?.websocket?.unsubscribe(hash)
+ // }
- async unsubscribeAll(): Promise {
- const $nip66: Nip66 = get(nip66)
- const promises: Promise[] = []
- for(const id of this._subIds) {
- promises.push($nip66.adapters?.websocket?.unsubscribe(id))
- }
- await Promise.all(promises)
- this._subIds = []
- }
+ // async unsubscribeAll(): Promise {
+ // const $nip66: Nip66 = get(nip66)
+ // const promises: Promise[] = []
+ // this.unsubscribeMany(this._subIds)
+ // }
async feed(user: User, limit: number = 1, until?: number): Promise {
const { relays } = user
const notes = await this.userNotes(user, limit, until)
- const relatives: IEvent[][] = [[]]
-
return notes
.map((_note: IEvent, index: number) => {
const note = new NostrEvent(_note, { relays: relays ?? [] })
@@ -102,7 +97,7 @@ export class UserService extends Service {
const reactions = relatives.filter(rel => rel.kind === 7);
const zaps = relatives.filter(rel => rel.kind === 9735 || rel.kind === 9321);
const comments = relatives.filter(rel => rel.kind === 1 || rel.kind === 1111);
- return { reactions, zaps, comments};
+ return { reactions, zaps, comments };
}
return { user, note, fetchRelatives };
})
diff --git a/libraries/nip66/src/core/WebsocketAdapter.ts b/libraries/nip66/src/core/WebsocketAdapter.ts
index 2a509920..37fa459b 100644
--- a/libraries/nip66/src/core/WebsocketAdapter.ts
+++ b/libraries/nip66/src/core/WebsocketAdapter.ts
@@ -151,14 +151,11 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
}
async shutdown(): Promise {
- console.log('shutting down websocket adapter')
- console.log('unsubscribing all...')
await this.unsubscribeAll();
- console.log('aborting...')
await this.abort();
- console.log('terminating worker...')
await delay(1000);
this.terminate()
+ await delay(100);
}
async abort(): Promise {
@@ -195,13 +192,15 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
}
async subscribe(args: WebsocketRequestBody = defaultWebsocketRequestBody, callbacks?: SubscribeHandlers): Promise{
+ let { hash } = args
if(callbacks && Object.keys(callbacks).length > 0) {
args.options.stream = true
}
- const hash = this.request({
+ const hash_ = this.request({
action: 'subscribe',
args
})
+ if(!hash) hash = hash_
if(this.subscriptions.has(hash)) {
console.warn(`[WebsocketAdapter] Already subscribed to ${hash}`)
return true;
@@ -238,15 +237,10 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
message.args.hash = deterministicHash(message?.args?.filters ?? {})
}
const { hash } = message.args
- //console.log('HASH', hash)
if(!this?.worker) {
console.warn('[WebsocketAdapter] Error sending command: no worker found')
return hash
- }
- //console.log('adding subscription', hash)
-
-
- //console.log(`[WebsocketAdapter:${this.constructor.name}] o/o SEND: ${message.action} -> websocketWorker`, message.args.filters)
+ }
if(this.worker instanceof Worker)
this.worker.postMessage(message)
else if(this.worker instanceof SharedWorker)
@@ -255,11 +249,9 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
}
async response(hash: string, callbacks?: SubscribeHandlers): Promise{
- //console.log('response', hash)
return new Promise( resolve => {
const results: any[] = []
const responseHandler = (message: WebsocketResponseBody) => {
- //console.log('websocket adapter response handler...')
let { result, type } = message
if(type === 'unsubscribed'){
return true
@@ -268,9 +260,7 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
return true
}
if(type === 'events') {
- //console.log(`websocket adapter: events`)
if(callbacks?.onevents){
- //console.log(`websocket adapter: onevents(${result.length})`)
callbacks.onevents(result)
return
}
@@ -292,9 +282,7 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
}
}
else if(type == 'complete'){
- //console.log('deleting subscription:', hash)
this.subscriptions.delete(hash)
- //console.log('complete: removing handler.', hash)
StateManager.off(hash)
if(callbacks?.onevent){
resolve(true)
diff --git a/libraries/nip66/src/services/Service.ts b/libraries/nip66/src/services/Service.ts
index 906ad2a2..b38a221b 100644
--- a/libraries/nip66/src/services/Service.ts
+++ b/libraries/nip66/src/services/Service.ts
@@ -78,17 +78,22 @@ export class Service {
}
async subscribe(args: FetchOptions, callbacks?: SubscribeHandlers): Promise {
+ console.log(`Service.subscribe()`)
await this.ready();
+ console.log(`Service: is ready`)
let { filters, relays, options, hash } = args;
- if(filters) {
- this.fetchFromCache(filters, callbacks);
- }
if(!hash) {
hash = deterministicHash(args)
+ console.log('Service.subscribe:hash', hash)
}
- const message: WebsocketRequestBody = { filters, relays, options, hash };
+ console.log('Service add hash', hash)
this.subscriptions.add(hash)
+ if(filters) {
+ this.fetchFromCache(filters, callbacks);
+ }
+ const message: WebsocketRequestBody = { filters, relays, options, hash };
const result = await this.websocketAdapter.subscribe(message, callbacks);
+ console.log('Service delete hash', hash)
this.subscriptions.delete(hash)
return typeof result === 'boolean'? []: result;
}
@@ -98,6 +103,13 @@ export class Service {
this.websocketAdapter.unsubscribe(hash);
}
+ async unsubscribeMany(hashes: string[]) {
+ await this.ready();
+ hashes.forEach((hash) => {
+ this.unsubscribe(hash);
+ })
+ }
+
async unsubscribeAllActive(){
await this.ready();
this.subscriptions.forEach((hash) => {
diff --git a/libraries/nocap/src/classes/Base.ts b/libraries/nocap/src/classes/Base.ts
index 9a4a6bab..4cdcd3d8 100644
--- a/libraries/nocap/src/classes/Base.ts
+++ b/libraries/nocap/src/classes/Base.ts
@@ -297,7 +297,6 @@ export default class Base {
}
this.precheck(key)
.then(async () => {
- console.log('seriously wtf fuck this.')
this.logger.debug(`${key}: precheck resolved`);
this.latency.start(key);
this.logger.debug(`${key}: this.adapters[${adapter}][${this.checkKey(key)}]()`);