mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-17 05:54:19 +01:00
feat: add future event when the time comes
This commit is contained in:
@@ -7,6 +7,7 @@ import useConfig from '@/core/useConfig';
|
|||||||
import { sortEvents } from '@/nostr/event/comparator';
|
import { sortEvents } from '@/nostr/event/comparator';
|
||||||
import usePool from '@/nostr/usePool';
|
import usePool from '@/nostr/usePool';
|
||||||
import useStats from '@/nostr/useStats';
|
import useStats from '@/nostr/useStats';
|
||||||
|
import epoch from '@/utils/epoch';
|
||||||
|
|
||||||
import type { Event as NostrEvent, Filter, SubscriptionOptions } from 'nostr-tools';
|
import type { Event as NostrEvent, Filter, SubscriptionOptions } from 'nostr-tools';
|
||||||
|
|
||||||
@@ -60,8 +61,16 @@ const useSubscription = (propsProvider: () => UseSubscriptionProps | null) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const addEvent = (event: NostrEvent) => {
|
const addEvent = (event: NostrEvent) => {
|
||||||
|
const SecondsToIgnore = 300; // 5 min
|
||||||
const limit = propsProvider()?.limit ?? 50;
|
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) => {
|
setEvents((current) => {
|
||||||
const sorted = utils.insertEventIntoDescendingList(current, event).slice(0, limit);
|
const sorted = utils.insertEventIntoDescendingList(current, event).slice(0, limit);
|
||||||
// FIXME なぜか重複して取得される問題があるが一旦uniqByで対処
|
// FIXME なぜか重複して取得される問題があるが一旦uniqByで対処
|
||||||
|
|||||||
Reference in New Issue
Block a user