mirror of
https://github.com/BlowaterNostr/blowater.git
synced 2024-10-18 15:43:20 +00:00
Update nostr.ts & fix dangling promise of subscription channels (#202)
This commit is contained in:
parent
919e4f672e
commit
ea741e69ff
@ -8,26 +8,15 @@ export class EventSyncer {
|
||||
constructor(private readonly pool: ConnectionPool, private readonly db: Database_Contextual_View) {}
|
||||
|
||||
syncEvent(id: NoteID) {
|
||||
const subID = EventSyncer.name + ":syncEvent";
|
||||
for (const e of this.db.events) {
|
||||
if (e.id == id.hex) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return (async () => {
|
||||
let events: Error | {
|
||||
filter: NostrFilters;
|
||||
chan: Channel<{
|
||||
res: RelayResponse_REQ_Message;
|
||||
url: string;
|
||||
}>;
|
||||
} = await this.pool.newSub("EventSyncer", {
|
||||
ids: [id.hex],
|
||||
});
|
||||
if (events instanceof SubscriptionAlreadyExist) {
|
||||
events = await this.pool.updateSub("EventSyncer", {
|
||||
ids: [id.hex],
|
||||
});
|
||||
}
|
||||
await this.pool.closeSub(subID);
|
||||
let events = await this.pool.newSub(subID, { ids: [id.hex] });
|
||||
if (events instanceof Error) {
|
||||
return events;
|
||||
}
|
||||
@ -35,11 +24,6 @@ export class EventSyncer {
|
||||
if (res.type != "EVENT") {
|
||||
continue;
|
||||
}
|
||||
const ok = await verifyEvent(res.event);
|
||||
if (!ok) {
|
||||
console.warn(res.event, url, "not valid");
|
||||
continue;
|
||||
}
|
||||
await this.db.addEvent(res.event);
|
||||
return; // just need to read from 1 relay
|
||||
}
|
||||
@ -47,16 +31,8 @@ export class EventSyncer {
|
||||
}
|
||||
|
||||
async syncEvents(filter: NostrFilters) {
|
||||
let events: Error | {
|
||||
filter: NostrFilters;
|
||||
chan: Channel<{
|
||||
res: RelayResponse_REQ_Message;
|
||||
url: string;
|
||||
}>;
|
||||
} = await this.pool.newSub("syncEvents", filter);
|
||||
if (events instanceof SubscriptionAlreadyExist) {
|
||||
events = await this.pool.updateSub("syncEvents", filter);
|
||||
}
|
||||
await this.pool.closeSub(EventSyncer.name);
|
||||
let events = await this.pool.newSub(EventSyncer.name, filter);
|
||||
if (events instanceof Error) {
|
||||
return events;
|
||||
}
|
||||
@ -64,11 +40,6 @@ export class EventSyncer {
|
||||
if (res.type != "EVENT") {
|
||||
continue;
|
||||
}
|
||||
const ok = await verifyEvent(res.event);
|
||||
if (!ok) {
|
||||
console.warn(res.event, url, "not valid");
|
||||
continue;
|
||||
}
|
||||
await this.db.addEvent(res.event);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ export class ProfilesSyncer {
|
||||
constructor(
|
||||
private readonly database: Database_Contextual_View,
|
||||
private readonly pool: ConnectionPool,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
async add(...users: string[]) {
|
||||
const size = this.userSet.size;
|
||||
@ -21,13 +22,11 @@ export class ProfilesSyncer {
|
||||
if (this.userSet.size == size) {
|
||||
return;
|
||||
}
|
||||
const resp = await this.pool.updateSub(
|
||||
"profilesStream",
|
||||
{
|
||||
authors: Array.from(this.userSet),
|
||||
kinds: [NostrKind.META_DATA],
|
||||
},
|
||||
);
|
||||
await this.pool.closeSub(ProfilesSyncer.name);
|
||||
const resp = await this.pool.newSub(ProfilesSyncer.name, {
|
||||
authors: Array.from(this.userSet),
|
||||
kinds: [NostrKind.META_DATA],
|
||||
});
|
||||
if (resp instanceof Error) {
|
||||
console.error(resp.message);
|
||||
return;
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit c1047e8348d89be7934516e1f5ddda26eb14b75c
|
||||
Subproject commit 95603f6c6cca8b4affba80502a7906cca1f92bb3
|
Loading…
Reference in New Issue
Block a user