diff --git a/src/app.ts b/src/app.ts index f4e99dc..1006862 100644 --- a/src/app.ts +++ b/src/app.ts @@ -44,7 +44,12 @@ import { instanceController } from './controllers/api/instance.ts'; import { mediaController } from './controllers/api/media.ts'; import { notificationsController } from './controllers/api/notifications.ts'; import { createTokenController, oauthAuthorizeController, oauthController } from './controllers/api/oauth.ts'; -import { configController, frontendConfigController, updateConfigController } from './controllers/api/pleroma.ts'; +import { + configController, + frontendConfigController, + pleromaAdminDeleteStatusController, + updateConfigController, +} from './controllers/api/pleroma.ts'; import { preferencesController } from './controllers/api/preferences.ts'; import { relayController } from './controllers/nostr/relay.ts'; import { searchController } from './controllers/api/search.ts'; @@ -189,6 +194,7 @@ app.get('/api/v1/blocks', requirePubkey, blocksController); app.get('/api/v1/admin/accounts', adminAccountsController); app.get('/api/v1/pleroma/admin/config', requireRole('admin'), configController); app.post('/api/v1/pleroma/admin/config', requireRole('admin'), updateConfigController); +app.delete('/api/v1/pleroma/admin/statuses/:id', requireRole('admin'), pleromaAdminDeleteStatusController); // Not (yet) implemented. app.get('/api/v1/custom_emojis', emptyArrayController); diff --git a/src/controllers/api/pleroma.ts b/src/controllers/api/pleroma.ts index cc6addb..b9656da 100644 --- a/src/controllers/api/pleroma.ts +++ b/src/controllers/api/pleroma.ts @@ -85,4 +85,13 @@ const updateConfigController: AppController = async (c) => { return c.json({ configs: newConfigs, need_reboot: false }); }; -export { configController, frontendConfigController, updateConfigController }; +const pleromaAdminDeleteStatusController: AppController = async (c) => { + await createAdminEvent({ + kind: 5, + tags: [['e', c.req.param('id')]], + }, c); + + return c.json({}); +}; + +export { configController, frontendConfigController, pleromaAdminDeleteStatusController, updateConfigController }; diff --git a/src/pipeline.ts b/src/pipeline.ts index 79b88c7..3333bec 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -66,12 +66,11 @@ async function storeEvent(event: Event, data: EventData, opts: StoreEventOpts = const { force = false } = opts; if (force || data.user || isAdminEvent(event) || await isLocallyFollowed(event.pubkey)) { - const [deletion] = await eventsDB.filter( - [{ kinds: [5], authors: [event.pubkey], '#e': [event.id], limit: 1 }], - { limit: 1 }, - ); + const isDeleted = await eventsDB.count( + [{ kinds: [5], authors: [Conf.pubkey, event.pubkey], '#e': [event.id], limit: 1 }], + ) > 0; - if (deletion) { + if (isDeleted) { return Promise.reject(new RelayError('blocked', 'event was deleted')); } else { await Promise.all([ @@ -88,13 +87,18 @@ async function storeEvent(event: Event, data: EventData, opts: StoreEventOpts = async function processDeletions(event: Event): Promise { if (event.kind === 5) { const ids = getTagSet(event.tags, 'e'); - const events = await eventsDB.filter([{ ids: [...ids] }]); - const deleteIds = events - .filter(({ pubkey, id }) => pubkey === event.pubkey && ids.has(id)) - .map((event) => event.id); + if (event.pubkey === Conf.pubkey) { + await eventsDB.deleteFilters([{ ids: [...ids] }]); + } else { + const events = await eventsDB.filter([{ + ids: [...ids], + authors: [event.pubkey], + }]); - await eventsDB.deleteFilters([{ ids: deleteIds }]); + const deleteIds = events.map(({ id }) => id); + await eventsDB.deleteFilters([{ ids: deleteIds }]); + } } }