diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index c81dedd..be8dbd9 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -181,7 +181,7 @@ const reblogStatusController: AppController = async (c) => { kind: 1, }); - if (event == undefined) { + if (!event) { return c.json({ error: 'Event not found.' }, 404); } @@ -189,11 +189,10 @@ const reblogStatusController: AppController = async (c) => { const reblogEvent = await createEvent({ kind: 6, - content: JSON.stringify(event), tags, }, c); - const status = await renderReblog(reblogEvent, reblogEvent.pubkey); + const status = await renderReblog(reblogEvent); return c.json(status); }; diff --git a/src/controllers/api/timelines.ts b/src/controllers/api/timelines.ts index 9dd0739..78a1fa9 100644 --- a/src/controllers/api/timelines.ts +++ b/src/controllers/api/timelines.ts @@ -57,8 +57,8 @@ async function renderStatuses(c: AppContext, filters: NostrFilter[]) { } const statuses = await Promise.all(events.map((event) => { - if (event.kind == 6) { - return renderReblog(event, c.get('pubkey')); + if (event.kind === 6) { + return renderReblog(event) } return renderStatus(event, c.get('pubkey')); })); diff --git a/src/interfaces/DittoEvent.ts b/src/interfaces/DittoEvent.ts index cdd4002..ca38a42 100644 --- a/src/interfaces/DittoEvent.ts +++ b/src/interfaces/DittoEvent.ts @@ -22,4 +22,5 @@ export interface DittoEvent extends NostrEvent { event_stats?: EventStats; d_author?: DittoEvent; user?: DittoEvent; + repost?: NostrEvent; } diff --git a/src/views/mastodon/statuses.ts b/src/views/mastodon/statuses.ts index cafd71e..b4126e1 100644 --- a/src/views/mastodon/statuses.ts +++ b/src/views/mastodon/statuses.ts @@ -4,7 +4,7 @@ import { Conf } from '@/config.ts'; import { nip19 } from '@/deps.ts'; import { type DittoEvent } from '@/interfaces/DittoEvent.ts'; import { getMediaLinks, parseNoteContent } from '@/note.ts'; -import { getAuthor } from '@/queries.ts'; +import { getAuthor, getEvent } from '@/queries.ts'; import { jsonMediaDataSchema } from '@/schemas/nostr.ts'; import { eventsDB } from '@/storages.ts'; import { findReplyTag } from '@/tags.ts'; @@ -98,15 +98,24 @@ async function renderStatus(event: DittoEvent, viewerPubkey?: string) { }; } -async function renderReblog(event: DittoEvent, viewerPubkey?: string) { - if (event.author == undefined) return; +async function renderReblog(event: DittoEvent) { + if (!event.author) return; - const reblog = await renderStatus(JSON.parse(event.content), viewerPubkey); + for (let i = 0; i < event.tags.length; i++) { + if (event.tags[i][0] === 'e') { + event.repost = await getEvent(event.tags[i][1], {kind:1}) + break + } + } + + if (!event.repost) return; + + const reblog = await renderStatus(event.repost); return { id: event.id, account: await renderAccount(event.author), reblogged: true, - reblog, + reblog }; }