From a515df1b3834f84519bd2601ce2e776b3696eb96 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Wed, 18 Sep 2024 15:45:14 +0700 Subject: [PATCH] Hydrated actor and attributedTo properties ref https://linear.app/tryghost/issue/AP-393 The string id isn't useful for the client, so we need to hydrate these to full objects. --- src/handlers.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/handlers.ts b/src/handlers.ts index 735e65da..1816c8ea 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -398,6 +398,28 @@ async function buildInboxItem( item.object = await db.get([item.object]) ?? item.object; } + if (typeof thing.actor === 'string') { + const actor = await lookupActor(apCtx, thing.actor); + + if (actor) { + const json = await actor.toJsonLd(); + if (typeof json === 'object' && json !== null) { + thing.actor = json; + } + } + } + + if (typeof thing.object !== 'string' && typeof thing.object.attributedTo === 'string') { + const actor = await lookupActor(apCtx, thing.object.attributedTo); + + if (actor) { + const json = await actor.toJsonLd(); + if (typeof json === 'object' && json !== null) { + thing.object.attributedTo = json; + } + } + } + // If the object associated with the item is an object with a content property, // we should sanitize the content to prevent XSS (in case it contains HTML) if (item.object && typeof item.object !== 'string' && item.object.content) {