pipeline: let the admin pubkey delete anything with kind 5's

This commit is contained in:
Alex Gleason 2024-01-11 19:05:34 -06:00
parent 31a6d0305f
commit c4920ccb2e
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -66,12 +66,11 @@ async function storeEvent(event: Event, data: EventData, opts: StoreEventOpts =
const { force = false } = opts; const { force = false } = opts;
if (force || data.user || isAdminEvent(event) || await isLocallyFollowed(event.pubkey)) { if (force || data.user || isAdminEvent(event) || await isLocallyFollowed(event.pubkey)) {
const [deletion] = await eventsDB.filter( const isDeleted = await eventsDB.count(
[{ kinds: [5], authors: [event.pubkey], '#e': [event.id], limit: 1 }], [{ kinds: [5], authors: [Conf.pubkey, event.pubkey], '#e': [event.id], limit: 1 }],
{ limit: 1 }, ) > 0;
);
if (deletion) { if (isDeleted) {
return Promise.reject(new RelayError('blocked', 'event was deleted')); return Promise.reject(new RelayError('blocked', 'event was deleted'));
} else { } else {
await Promise.all([ await Promise.all([
@ -88,12 +87,13 @@ async function storeEvent(event: Event, data: EventData, opts: StoreEventOpts =
async function processDeletions(event: Event): Promise<void> { async function processDeletions(event: Event): Promise<void> {
if (event.kind === 5) { if (event.kind === 5) {
const ids = getTagSet(event.tags, 'e'); const ids = getTagSet(event.tags, 'e');
const events = await eventsDB.filter([{ ids: [...ids] }]);
const deleteIds = events const events = await eventsDB.filter([{
.filter(({ pubkey, id }) => pubkey === event.pubkey && ids.has(id)) ids: [...ids],
.map((event) => event.id); authors: [Conf.pubkey, event.pubkey],
}]);
const deleteIds = events.map(({ id }) => id);
await eventsDB.deleteFilters([{ ids: deleteIds }]); await eventsDB.deleteFilters([{ ids: deleteIds }]);
} }
} }