Skip to content

Commit

Permalink
Hydrated actor and attributedTo properties
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
allouis committed Sep 19, 2024
1 parent 44a6a36 commit a515df1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a515df1

Please sign in to comment.