Support reactionsController with a single emoji

This commit is contained in:
Alex Gleason 2024-05-23 13:22:04 -05:00
parent 86a931d725
commit b197b57ea8
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 9 additions and 2 deletions

View File

@ -211,8 +211,9 @@ app.get('/api/v1/mutes', requireSigner, mutesController);
app.get('/api/v1/markers', requireProof(), markersController);
app.post('/api/v1/markers', requireProof(), updateMarkersController);
app.put('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions/:emoji', requireSigner, reactionController);
app.get('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions', reactionsController);
app.get('/api/v1/pleroma/statuses/:id{[0-9a-f]{64}}/reactions/:emoji', reactionsController);
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);

View File

@ -89,9 +89,15 @@ const reactionsController: AppController = async (c) => {
const id = c.req.param('id');
const store = await Storages.db();
const pubkey = await c.get('signer')?.getPublicKey();
const emoji = c.req.param('emoji') as string | undefined;
if (typeof emoji === 'string' && !/^\p{RGI_Emoji}$/v.test(emoji)) {
return c.json({ error: 'Invalid emoji' }, 400);
}
const events = await store.query([{ kinds: [7], '#e': [id], limit: 100 }])
.then((events) => hydrateEvents({ events, store }));
.then((events) => hydrateEvents({ events, store }))
.then((events) => events.filter((event) => !emoji || event.content === emoji));
/** Events grouped by emoji. */
const byEmoji = events.reduce((acc, event) => {