From 5e0f1a1732d5fcf20b6ebe35c5e85333bace4bd8 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Thu, 16 May 2024 15:29:01 +0700 Subject: [PATCH] Used Actor object for actor in Activity ref https://linear.app/tryghost/issue/MOM-126 Similar to using the Article object for object in Activity, this allows us to more easily pull out all of the extra data for Actors. At the moment its the full JSONLD representation, but we can slim that down in future. --- .../src/core/activitypub/activity.entity.ts | 24 ++++++++++++++----- .../src/core/activitypub/actor.entity.ts | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ghost/ghost/src/core/activitypub/activity.entity.ts b/ghost/ghost/src/core/activitypub/activity.entity.ts index 1ab8b17811..42c019a6ad 100644 --- a/ghost/ghost/src/core/activitypub/activity.entity.ts +++ b/ghost/ghost/src/core/activitypub/activity.entity.ts @@ -1,4 +1,5 @@ import {Entity} from '../../common/entity.base'; +import {Actor} from './actor.entity'; import {Article} from './article.object'; import {ActivityPub} from './types'; import {URI} from './uri.object'; @@ -6,7 +7,7 @@ import {URI} from './uri.object'; type ActivityData = { activity: URI | null; type: ActivityPub.ActivityType; - actor: URI; + actor: Actor | URI; object: { id: URI; type: string; @@ -53,7 +54,21 @@ export class Activity extends Entity { return this.attr.object; } + getActor(url: URL) { + if (this.attr.actor instanceof Actor) { + return this.attr.actor.getJSONLD(url); + } + return { + type: 'Person', + id: this.attr.actor.getValue(url), + preferredUsername: 'index' + }; + } + get actorId() { + if (this.attr.actor instanceof Actor) { + return this.attr.actor.actorId; + } return this.attr.actor; } @@ -70,15 +85,12 @@ export class Activity extends Entity { getJSONLD(url: URL): ActivityPub.Activity { const object = this.getObject(url); + const actor = this.getActor(url); return { '@context': 'https://www.w3.org/ns/activitystreams', id: this.activityId?.getValue(url) || null, type: this.attr.type, - actor: { - type: 'Person', - id: this.actorId.getValue(url), - username: `@index@${this.actorId.hostname}` - }, + actor: actor, object: { ...object, id: this.objectId.getValue(url) diff --git a/ghost/ghost/src/core/activitypub/actor.entity.ts b/ghost/ghost/src/core/activitypub/actor.entity.ts index a2ba5ae3ac..6c4bc5c013 100644 --- a/ghost/ghost/src/core/activitypub/actor.entity.ts +++ b/ghost/ghost/src/core/activitypub/actor.entity.ts @@ -156,7 +156,7 @@ export class Actor extends Entity { activity: new URI(`activity/${new ObjectID().toHexString()}`), to: this.followersCollectionId, type: 'Create', - actor: this.actorId, + actor: this, object: article }); this.doActivity(activity);