Pass viewerPubkey to toStatus in more places

This commit is contained in:
Alex Gleason 2023-08-29 14:48:28 -05:00
parent 2ee29bf1e2
commit 9d714b6173
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 9 additions and 9 deletions

View File

@ -13,7 +13,7 @@ const notificationsController: AppController = async (c) => {
{ timeout: Time.seconds(3) }, { timeout: Time.seconds(3) },
); );
const statuses = await Promise.all(events.map(toNotification)); const statuses = await Promise.all(events.map((event) => toNotification(event, pubkey)));
return paginated(c, events, statuses); return paginated(c, events, statuses);
}; };

View File

@ -29,7 +29,7 @@ const statusController: AppController = async (c) => {
const event = await getEvent(id, { kind: 1 }); const event = await getEvent(id, { kind: 1 });
if (event) { if (event) {
return c.json(await toStatus(event)); return c.json(await toStatus(event, c.get('pubkey')));
} }
return c.json({ error: 'Event not found.' }, 404); return c.json({ error: 'Event not found.' }, 404);
@ -74,7 +74,7 @@ const createStatusController: AppController = async (c) => {
tags, tags,
}, c); }, c);
return c.json(await toStatus(event)); return c.json(await toStatus(event, c.get('pubkey')));
} else { } else {
return c.json({ error: 'Bad request', schema: result.error }, 400); return c.json({ error: 'Bad request', schema: result.error }, 400);
} }
@ -115,7 +115,7 @@ const favouriteController: AppController = async (c) => {
], ],
}, c); }, c);
const status = await toStatus(target); const status = await toStatus(target, c.get('pubkey'));
if (status) { if (status) {
status.favourited = true; status.favourited = true;

View File

@ -63,7 +63,7 @@ const streamingController: AppController = (c) => {
if (filter) { if (filter) {
for await (const event of Sub.sub(socket, '1', [filter])) { for await (const event of Sub.sub(socket, '1', [filter])) {
const status = await toStatus(event); const status = await toStatus(event, pubkey);
if (status) { if (status) {
send('update', status); send('update', status);
} }

View File

@ -287,15 +287,15 @@ async function toRelationship(sourcePubkey: string, targetPubkey: string) {
}; };
} }
function toNotification(event: Event) { function toNotification(event: Event, viewerPubkey?: string) {
switch (event.kind) { switch (event.kind) {
case 1: case 1:
return toNotificationMention(event as Event<1>); return toNotificationMention(event as Event<1>, viewerPubkey);
} }
} }
async function toNotificationMention(event: Event<1>) { async function toNotificationMention(event: Event<1>, viewerPubkey?: string) {
const status = await toStatus(event); const status = await toStatus(event, viewerPubkey);
if (!status) return; if (!status) return;
return { return {