2023-12-28 01:35:06 +00:00
|
|
|
import { Debug, type Event } from '@/deps.ts';
|
2023-12-17 17:00:04 +00:00
|
|
|
import { activeRelays, pool } from '@/pool.ts';
|
2023-08-29 21:40:23 +00:00
|
|
|
import { nostrNow } from '@/utils.ts';
|
2023-08-17 21:47:22 +00:00
|
|
|
|
|
|
|
import * as pipeline from './pipeline.ts';
|
2023-07-25 20:30:58 +00:00
|
|
|
|
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.
|
2023-08-14 19:11:28 +00:00
|
|
|
pool.subscribe(
|
2023-08-29 21:40:23 +00:00
|
|
|
[{ kinds: [0, 1, 3, 5, 6, 7, 10002], limit: 0, since: nostrNow() }],
|
2023-12-17 17:00:04 +00:00
|
|
|
activeRelays,
|
2023-07-26 17:54:06 +00:00
|
|
|
handleEvent,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
);
|
2023-07-25 20:30:58 +00:00
|
|
|
|
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(() => {});
|
2023-08-14 19:11:28 +00:00
|
|
|
}
|