mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add delete reaction controller
This commit is contained in:
parent
93922b3f93
commit
b0a53f4789
2 changed files with 49 additions and 2 deletions
|
|
@ -43,6 +43,7 @@ import {
|
||||||
updateConfigController,
|
updateConfigController,
|
||||||
} from '@/controllers/api/pleroma.ts';
|
} from '@/controllers/api/pleroma.ts';
|
||||||
import { preferencesController } from '@/controllers/api/preferences.ts';
|
import { preferencesController } from '@/controllers/api/preferences.ts';
|
||||||
|
import { deleteReactionController, reactionController } from '@/controllers/api/reactions.ts';
|
||||||
import { relayController } from '@/controllers/nostr/relay.ts';
|
import { relayController } from '@/controllers/nostr/relay.ts';
|
||||||
import {
|
import {
|
||||||
adminReportController,
|
adminReportController,
|
||||||
|
|
@ -210,6 +211,9 @@ app.get('/api/v1/mutes', requireSigner, mutesController);
|
||||||
app.get('/api/v1/markers', requireProof(), markersController);
|
app.get('/api/v1/markers', requireProof(), markersController);
|
||||||
app.post('/api/v1/markers', requireProof(), updateMarkersController);
|
app.post('/api/v1/markers', requireProof(), updateMarkersController);
|
||||||
|
|
||||||
|
app.put('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions/:emoji', requireSigner, reactionController);
|
||||||
|
app.delete('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions/:emoji', requireSigner, deleteReactionController);
|
||||||
|
|
||||||
app.get('/api/v1/admin/accounts', requireRole('admin'), adminAccountsController);
|
app.get('/api/v1/admin/accounts', requireRole('admin'), adminAccountsController);
|
||||||
app.get('/api/v1/pleroma/admin/config', requireRole('admin'), configController);
|
app.get('/api/v1/pleroma/admin/config', requireRole('admin'), configController);
|
||||||
app.post('/api/v1/pleroma/admin/config', requireRole('admin'), updateConfigController);
|
app.post('/api/v1/pleroma/admin/config', requireRole('admin'), updateConfigController);
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ const reactionController: AppController = async (c) => {
|
||||||
|
|
||||||
await createEvent({
|
await createEvent({
|
||||||
kind: 7,
|
kind: 7,
|
||||||
content: '',
|
content: emoji,
|
||||||
created_at: Math.floor(Date.now() / 1000),
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
tags: [['e', id]],
|
tags: [['e', id]],
|
||||||
}, c);
|
}, c);
|
||||||
|
|
@ -35,4 +35,47 @@ const reactionController: AppController = async (c) => {
|
||||||
return c.json(status);
|
return c.json(status);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { reactionController };
|
/**
|
||||||
|
* Delete reactions to a status.
|
||||||
|
* https://docs.pleroma.social/backend/development/API/pleroma_api/#delete-apiv1pleromastatusesidreactionsemoji
|
||||||
|
*/
|
||||||
|
const deleteReactionController: AppController = async (c) => {
|
||||||
|
const id = c.req.param('id');
|
||||||
|
const emoji = c.req.param('emoji');
|
||||||
|
const signer = c.get('signer')!;
|
||||||
|
const pubkey = await signer.getPublicKey();
|
||||||
|
const store = await Storages.db();
|
||||||
|
|
||||||
|
if (!/^\p{RGI_Emoji}$/v.test(emoji)) {
|
||||||
|
return c.json({ error: 'Invalid emoji' }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [event] = await store.query([
|
||||||
|
{ kinds: [1], ids: [id], limit: 1 },
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!event) {
|
||||||
|
return c.json({ error: 'Status not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const events = await store.query([
|
||||||
|
{ kinds: [7], authors: [pubkey], '#e': [id] },
|
||||||
|
]);
|
||||||
|
|
||||||
|
const tags = events
|
||||||
|
.filter((event) => event.content === emoji)
|
||||||
|
.map((event) => ['e', event.id]);
|
||||||
|
|
||||||
|
await createEvent({
|
||||||
|
kind: 5,
|
||||||
|
content: '',
|
||||||
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
|
tags,
|
||||||
|
}, c);
|
||||||
|
|
||||||
|
const status = renderStatus(event, { viewerPubkey: pubkey });
|
||||||
|
|
||||||
|
return c.json(status);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { deleteReactionController, reactionController };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue