Make notifications kind of work

This commit is contained in:
Alex Gleason 2023-08-28 15:56:38 -05:00
parent 2029c73eab
commit a075c533e6
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 38 additions and 3 deletions

View File

@ -1,7 +1,22 @@
import { type AppController } from '@/app.ts'; 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) => { const notificationsController: AppController = async (c) => {
return c.json([]); 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 }; export { notificationsController };

View File

@ -276,4 +276,24 @@ async function toRelationship(sourcePubkey: string, targetPubkey: string) {
}; };
} }
export { toAccount, toRelationship, toStatus }; function toNotification(event: Event) {
switch (event.kind) {
case 1:
return toNotificationMention(event as Event<1>);
}
}
async function toNotificationMention(event: Event<1>) {
const status = await toStatus(event);
if (!status) return;
return {
id: event.id,
type: 'mention',
created_at: nostrDate(event.created_at).toISOString(),
account: status.account,
status: status,
};
}
export { toAccount, toNotification, toRelationship, toStatus };