ditto/src/firehose.ts

28 lines
768 B
TypeScript
Raw Normal View History

2023-12-28 01:35:06 +00:00
import { Debug, type Event } from '@/deps.ts';
import { activeRelays, pool } from '@/pool.ts';
import { nostrNow } from '@/utils.ts';
2023-08-17 21:47:22 +00:00
import * as pipeline from './pipeline.ts';
2023-12-28 01:35:06 +00:00
const debug = Debug('ditto:firehose');
2023-08-14 20:39:21 +00:00
// This file watches events on all known relays and performs
// side-effects based on them, such as trending hashtag tracking
// and storing events for notifications and the home feed.
pool.subscribe(
[{ kinds: [0, 1, 3, 5, 6, 7, 10002], limit: 0, since: nostrNow() }],
activeRelays,
handleEvent,
undefined,
undefined,
);
2023-08-14 16:02:09 +00:00
/** Handle events through the firehose pipeline. */
2023-08-17 21:47:22 +00:00
function handleEvent(event: Event): Promise<void> {
2023-12-28 01:35:06 +00:00
debug(`Event<${event.kind}> ${event.id}`);
2023-08-18 01:28:23 +00:00
return pipeline
.handleEvent(event)
.catch(() => {});
}