pipeline: broadcast deletions to all known relays

This commit is contained in:
Alex Gleason
2023-09-05 21:38:15 -05:00
parent e2b88d57d9
commit a69b7f54f8
2 changed files with 24 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ import * as eventsDB from '@/db/events.ts';
import { addRelays } from '@/db/relays.ts';
import { findUser } from '@/db/users.ts';
import { type Event, LRUCache } from '@/deps.ts';
import { publish } from '@/firehose.ts';
import { isEphemeralKind } from '@/kinds.ts';
import * as mixer from '@/mixer.ts';
import { isLocallyFollowed } from '@/queries.ts';
@@ -27,6 +28,7 @@ async function handleEvent(event: Event): Promise<void> {
trackRelays(event),
trackHashtags(event),
streamOut(event, data),
broadcast(event, data),
]);
}
@@ -130,6 +132,18 @@ function streamOut(event: Event, data: EventData) {
}
}
/**
* Publish the event to other relays.
* This should only be done in certain circumstances, like mentioning a user or publishing deletions.
*/
function broadcast(event: Event, data: EventData) {
if (!data.user || !isFresh(event)) return;
if (event.kind === 5) {
publish(event);
}
}
/** NIP-20 command line result. */
class RelayError extends Error {
constructor(prefix: 'duplicate' | 'pow' | 'blocked' | 'rate-limited' | 'invalid' | 'error', message: string) {