mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add GET /api/v1/notifications/:id endpoint
This commit is contained in:
parent
30a5d9a20f
commit
a7d8d86fa7
2 changed files with 29 additions and 2 deletions
|
|
@ -60,7 +60,7 @@ import {
|
|||
import { markersController, updateMarkersController } from '@/controllers/api/markers.ts';
|
||||
import { mediaController, updateMediaController } from '@/controllers/api/media.ts';
|
||||
import { mutesController } from '@/controllers/api/mutes.ts';
|
||||
import { notificationsController } from '@/controllers/api/notifications.ts';
|
||||
import { notificationController, notificationsController } from '@/controllers/api/notifications.ts';
|
||||
import { createTokenController, oauthAuthorizeController, oauthController } from '@/controllers/api/oauth.ts';
|
||||
import {
|
||||
configController,
|
||||
|
|
@ -273,6 +273,8 @@ app.get('/api/v1/suggestions', suggestionsV1Controller);
|
|||
app.get('/api/v2/suggestions', suggestionsV2Controller);
|
||||
|
||||
app.get('/api/v1/notifications', requireSigner, notificationsController);
|
||||
app.get('/api/v1/notifications/:id', requireSigner, notificationController);
|
||||
|
||||
app.get('/api/v1/favourites', requireSigner, favouritesController);
|
||||
app.get('/api/v1/bookmarks', requireSigner, bookmarksController);
|
||||
app.get('/api/v1/blocks', requireSigner, blocksController);
|
||||
|
|
|
|||
|
|
@ -74,6 +74,31 @@ const notificationsController: AppController = async (c) => {
|
|||
return renderNotifications(filters, types, params, c);
|
||||
};
|
||||
|
||||
const notificationController: AppController = async (c) => {
|
||||
const id = c.req.param('id');
|
||||
const pubkey = await c.get('signer')?.getPublicKey()!;
|
||||
const store = c.get('store');
|
||||
|
||||
// Remove the timestamp from the ID.
|
||||
const eventId = id.replace(/^\d+-/, '');
|
||||
|
||||
const [event] = await store.query([{ ids: [eventId] }]);
|
||||
|
||||
if (!event) {
|
||||
return c.json({ error: 'Event not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
await hydrateEvents({ events: [event], store });
|
||||
|
||||
const notification = await renderNotification(event, { viewerPubkey: pubkey });
|
||||
|
||||
if (!notification) {
|
||||
return c.json({ error: 'Notification not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
return c.json(notification);
|
||||
};
|
||||
|
||||
async function renderNotifications(
|
||||
filters: NostrFilter[],
|
||||
types: Set<string>,
|
||||
|
|
@ -106,4 +131,4 @@ async function renderNotifications(
|
|||
return paginated(c, events, notifications);
|
||||
}
|
||||
|
||||
export { notificationsController };
|
||||
export { notificationController, notificationsController };
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue