Skip to content

Commit

Permalink
handle events coming in with the same created_at and different IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
pablof7z committed Aug 2, 2024
1 parent 08b3a2e commit 3ab0989
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ndk-svelte/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,18 @@ class NDKSvelte extends NDK {
if (eventIds.has(dedupKey)) {
const prevEvent = events.find((e) => e.deduplicationKey() === dedupKey);

if (prevEvent && prevEvent.created_at! < event.created_at!) {
// remove the previous event
const index = events.findIndex((e) => e.deduplicationKey() === dedupKey);
events.splice(index, 1);
if (prevEvent) {
if (prevEvent.created_at! < event.created_at!) {
// remove the previous event
const index = events.findIndex((e) => e.deduplicationKey() === dedupKey);
events.splice(index, 1);
} else if (prevEvent.created_at! === event.created_at! && prevEvent.id !== event.id) {
// we have an event with the same created_at but different id, which might be a bug
// in some relays but take the incoming event anyway
console.warn("Received event with same created_at but different id", { prevId: prevEvent.id, newId: event.id });
const index = events.findIndex((e) => e.deduplicationKey() === dedupKey);
events.splice(index, 1);
}
} else {
return;
}
Expand Down

0 comments on commit 3ab0989

Please sign in to comment.