Make notifications kind of work

This commit is contained in:
Alex Gleason
2023-08-28 15:56:38 -05:00
parent 2029c73eab
commit a075c533e6
2 changed files with 38 additions and 3 deletions

View File

@@ -1,7 +1,22 @@
import { type AppController } from '@/app.ts';
import * as mixer from '@/mixer.ts';
import { buildLinkHeader, paginationSchema } from '@/utils/web.ts';
import { toNotification } from '@/transformers/nostr-to-mastoapi.ts';
import { Time } from '@/utils.ts';
const notificationsController: AppController = (c) => {
return c.json([]);
const notificationsController: AppController = async (c) => {
const pubkey = c.get('pubkey')!;
const { since, until } = paginationSchema.parse(c.req.query());
const events = await mixer.getFilters(
[{ kinds: [1], '#p': [pubkey], since, until }],
{ timeout: Time.seconds(3) },
);
const statuses = await Promise.all(events.map(toNotification));
const link = buildLinkHeader(c.req.url, events);
return c.json(statuses, 200, link ? { link } : undefined);
};
export { notificationsController };