mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-10 15:36:53 +02:00
fix: improve chat adapter reliability - prevent hangs and use all relay hints
- Add error and complete handlers to prevent subscription hangs - Merge relay hints from both identifier.relays and identifier.value.relays - Ensures events can be found even with limited relay availability - Fixes 'expects kind 1 not 1111' errors by using all available relay hints
This commit is contained in:
@@ -110,7 +110,11 @@ export class Nip10Adapter extends ChatProtocolAdapter {
|
||||
}
|
||||
|
||||
const pointer = identifier.value;
|
||||
const relayHints = identifier.relays || [];
|
||||
// Merge relay hints from both top-level and value (nevent encoding includes both)
|
||||
const relayHints = [
|
||||
...(identifier.relays || []),
|
||||
...(pointer.relays || []),
|
||||
];
|
||||
|
||||
// 1. Fetch the provided event
|
||||
const providedEvent = await this.fetchEvent(pointer.id, relayHints);
|
||||
@@ -792,6 +796,9 @@ export class Nip10Adapter extends ChatProtocolAdapter {
|
||||
sub.unsubscribe();
|
||||
resolve();
|
||||
},
|
||||
complete: () => {
|
||||
clearTimeout(timeout);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -136,7 +136,11 @@ export class Nip22Adapter extends ChatProtocolAdapter {
|
||||
}
|
||||
|
||||
const pointer = identifier.value;
|
||||
const relayHints = identifier.relays || [];
|
||||
// Merge relay hints from both top-level and value (nevent encoding includes both)
|
||||
const relayHints = [
|
||||
...(identifier.relays || []),
|
||||
...(pointer.relays || []),
|
||||
];
|
||||
|
||||
// 1. Fetch the root event
|
||||
let rootEvent: NostrEvent;
|
||||
@@ -544,6 +548,15 @@ export class Nip22Adapter extends ChatProtocolAdapter {
|
||||
resolve(response);
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
clearTimeout(timeout);
|
||||
sub.unsubscribe();
|
||||
console.error("[NIP-22] Subscription error:", err);
|
||||
resolve(null);
|
||||
},
|
||||
complete: () => {
|
||||
clearTimeout(timeout);
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -599,6 +612,15 @@ export class Nip22Adapter extends ChatProtocolAdapter {
|
||||
resolve(response);
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
clearTimeout(timeout);
|
||||
sub.unsubscribe();
|
||||
console.error("[NIP-22] Subscription error:", err);
|
||||
resolve(null);
|
||||
},
|
||||
complete: () => {
|
||||
clearTimeout(timeout);
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user