Files
ditto/src/firehose.ts
2023-08-29 14:53:12 -05:00

28 lines
764 B
TypeScript

import { getActiveRelays } from '@/db/relays.ts';
import { type Event, RelayPool } from '@/deps.ts';
import * as pipeline from './pipeline.ts';
const relays = await getActiveRelays();
const pool = new RelayPool(relays);
// 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 }],
relays,
handleEvent,
undefined,
undefined,
);
/** Handle events through the firehose pipeline. */
function handleEvent(event: Event): Promise<void> {
console.info(`firehose: Event<${event.kind}> ${event.id}`);
return pipeline
.handleEvent(event)
.catch(() => {});
}