mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-21 15:34:21 +01:00
pipeline: process kind 5 deletion events
This commit is contained in:
@@ -7,6 +7,7 @@ import { isEphemeralKind } from '@/kinds.ts';
|
||||
import * as mixer from '@/mixer.ts';
|
||||
import { isLocallyFollowed } from '@/queries.ts';
|
||||
import { Sub } from '@/subs.ts';
|
||||
import { getTagSet } from '@/tags.ts';
|
||||
import { trends } from '@/trends.ts';
|
||||
import { eventAge, isRelay, nostrDate, Time } from '@/utils.ts';
|
||||
|
||||
@@ -22,6 +23,7 @@ async function handleEvent(event: Event): Promise<void> {
|
||||
|
||||
await Promise.all([
|
||||
storeEvent(event, data),
|
||||
processDeletions(event),
|
||||
trackRelays(event),
|
||||
trackHashtags(event),
|
||||
streamOut(event, data),
|
||||
@@ -67,6 +69,20 @@ async function storeEvent(event: Event, data: EventData): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Query to-be-deleted events, ensure their pubkey matches, then delete them from the database. */
|
||||
async function processDeletions(event: Event): Promise<void> {
|
||||
if (event.kind === 5) {
|
||||
const ids = getTagSet(event.tags, 'e');
|
||||
const events = await eventsDB.getFilters([{ ids: [...ids] }]);
|
||||
|
||||
const deleteIds = events
|
||||
.filter(({ pubkey, id }) => pubkey === event.pubkey && ids.has(id))
|
||||
.map((event) => event.id);
|
||||
|
||||
await eventsDB.deleteFilters([{ ids: deleteIds }]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Track whenever a hashtag is used, for processing trending tags. */
|
||||
function trackHashtags(event: Event): void {
|
||||
const date = nostrDate(event.created_at);
|
||||
|
||||
Reference in New Issue
Block a user