This commit is contained in:
commit
aa938034c5
@ -165,9 +165,18 @@ class IndexedDB extends Dexie {
|
||||
async find(filter: Filter, callback: (event: TaggedNostrEvent) => void): Promise<void> {
|
||||
if (!filter) return;
|
||||
|
||||
const filterString = JSON.stringify(filter);
|
||||
if (this.readQueue.has(filterString)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure only 1 argument is passed
|
||||
const cb = e => {
|
||||
this.seenEvents.add(e.id);
|
||||
if (filter.not?.ids?.includes(e.id)) {
|
||||
console.log("skipping", e.id);
|
||||
return;
|
||||
}
|
||||
callback(e);
|
||||
};
|
||||
|
||||
@ -225,7 +234,6 @@ class IndexedDB extends Dexie {
|
||||
query = query.limit(filter.limit);
|
||||
}
|
||||
// TODO test that the sort is actually working
|
||||
const filterString = JSON.stringify(filter);
|
||||
this.enqueueRead(filterString, async () => {
|
||||
await query.each(cb);
|
||||
});
|
||||
|
@ -319,8 +319,21 @@ export class NostrSystem extends EventEmitter<NostrSystemEvents> implements Syst
|
||||
qSend.filters = fNew;
|
||||
|
||||
fNew.forEach(f => {
|
||||
inMemoryDB.find(f, e => this.emit("event", "*", e));
|
||||
this.emit("request", f);
|
||||
const alreadyHave = inMemoryDB.findArray(f).map(e => {
|
||||
console.log("got from inMemoryDB", e);
|
||||
this.HandleEvent(e);
|
||||
return e.id;
|
||||
});
|
||||
let fCopy = { ...f }; // some relays reject the query if it contains an unknown key. only send locally.
|
||||
if (alreadyHave.length) {
|
||||
fCopy.not = fCopy.not ?? {};
|
||||
if (fCopy.not.ids) {
|
||||
fCopy.not.ids.push(...alreadyHave);
|
||||
} else {
|
||||
fCopy.not.ids = alreadyHave;
|
||||
}
|
||||
}
|
||||
this.emit("request", fCopy);
|
||||
});
|
||||
|
||||
if (qSend.relay) {
|
||||
|
@ -57,7 +57,8 @@ export interface ReqFilter {
|
||||
since?: number;
|
||||
until?: number;
|
||||
limit?: number;
|
||||
[key: string]: Array<string> | Array<number> | string | number | undefined;
|
||||
not?: ReqFilter;
|
||||
[key: string]: Array<string> | Array<number> | string | number | undefined | ReqFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user