From 068fe32dc9b91e647cb39832baffd6caaceef877 Mon Sep 17 00:00:00 2001 From: Shusui MOYATANI Date: Mon, 3 Jul 2023 21:21:20 +0900 Subject: [PATCH] fix: pickLatestEvent: compare id --- src/nostr/useBatchedEvents.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/nostr/useBatchedEvents.ts b/src/nostr/useBatchedEvents.ts index 1b29c36..79b77da 100644 --- a/src/nostr/useBatchedEvents.ts +++ b/src/nostr/useBatchedEvents.ts @@ -1,5 +1,3 @@ -import { createSignal, type Accessor, type Signal } from 'solid-js'; - import { type Event as NostrEvent, type Filter, Kind } from 'nostr-tools'; import useConfig from '@/core/useConfig'; @@ -147,7 +145,7 @@ const { addTask, removeTask } = useBatch(() => ({ }); }; - const { config, shouldMuteEvent } = useConfig(); + const { config } = useConfig(); const pool = usePool(); const sub = pool().sub(config().relayUrls, filters, {}); @@ -224,5 +222,10 @@ export const registerTask = ({ export const pickLatestEvent = (events: NostrEvent[]): NostrEvent | null => { if (events.length === 0) return null; - return events.reduce((a, b) => (a.created_at > b.created_at ? a : b)); + return events.reduce((a, b) => { + const diff = a.created_at - b.created_at; + if (diff > 0) return a; + if (diff < 0) return b; + return a.id < b.id ? a : b; + }); };