Make notifications kind of work
This commit is contained in:
parent
2029c73eab
commit
a075c533e6
|
@ -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 };
|
||||||
|
|
|
@ -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 };
|
||||||
|
|
Loading…
Reference in New Issue