feat: add future event when the time comes

This commit is contained in:
Shusui MOYATANI
2023-11-28 22:23:48 +09:00
parent e502c7bf58
commit c6ecb9fdf5

View File

@@ -7,6 +7,7 @@ import useConfig from '@/core/useConfig';
import { sortEvents } from '@/nostr/event/comparator';
import usePool from '@/nostr/usePool';
import useStats from '@/nostr/useStats';
import epoch from '@/utils/epoch';
import type { Event as NostrEvent, Filter, SubscriptionOptions } from 'nostr-tools';
@@ -60,8 +61,16 @@ const useSubscription = (propsProvider: () => UseSubscriptionProps | null) => {
});
const addEvent = (event: NostrEvent) => {
const SecondsToIgnore = 300; // 5 min
const limit = propsProvider()?.limit ?? 50;
const diffSec = event.created_at - epoch();
if (diffSec > SecondsToIgnore) return;
if (diffSec > 0) {
setTimeout(() => addEvent(event), diffSec * 1000);
return;
}
setEvents((current) => {
const sorted = utils.insertEventIntoDescendingList(current, event).slice(0, limit);
// FIXME なぜか重複して取得される問題があるが一旦uniqByで対処