2024-05-14 21:25:24 +00:00
|
|
|
import { Stickynotes } from '@soapbox/stickynotes';
|
2024-05-01 21:14:50 +00:00
|
|
|
|
2024-05-14 21:25:24 +00:00
|
|
|
import { Storages } from '@/storages.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
|
|
|
|
2024-05-14 21:25:24 +00:00
|
|
|
const console = new Stickynotes('ditto:firehose');
|
2023-12-28 01:35:06 +00:00
|
|
|
|
2024-05-14 21:25:24 +00:00
|
|
|
/**
|
|
|
|
* This function 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.
|
|
|
|
*/
|
|
|
|
export async function startFirehose() {
|
|
|
|
const store = await Storages.client();
|
2023-07-25 20:30:58 +00:00
|
|
|
|
2024-05-14 21:25:24 +00:00
|
|
|
for await (const msg of store.req([{ kinds: [0, 1, 3, 5, 6, 7, 9735, 10002], limit: 0, since: nostrNow() }])) {
|
|
|
|
if (msg[0] === 'EVENT') {
|
|
|
|
const event = msg[2];
|
|
|
|
console.debug(`NostrEvent<${event.kind}> ${event.id}`);
|
2023-12-28 01:35:06 +00:00
|
|
|
|
2024-05-14 21:25:24 +00:00
|
|
|
pipeline
|
|
|
|
.handleEvent(event, AbortSignal.timeout(5000))
|
|
|
|
.catch(() => {});
|
|
|
|
}
|
|
|
|
}
|
2023-08-14 19:11:28 +00:00
|
|
|
}
|