Used Article as Activity object

ref https://linear.app/tryghost/issue/MOM-126

This allows us to pull out all of the data when converting to JSONLD
This commit is contained in:
Fabien O'Carroll 2024-05-16 15:26:56 +07:00 committed by Fabien 'egg' O'Carroll
parent 8842dc2312
commit ea40c6ad65
2 changed files with 11 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import {Entity} from '../../common/entity.base';
import {Article} from './article.object';
import {ActivityPub} from './types';
import {URI} from './uri.object';
@ -11,7 +12,7 @@ type ActivityData = {
type: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[x: string]: any;
};
} | Article;
to: URI | null;
}
@ -45,7 +46,10 @@ export class Activity extends Entity<ActivityData> {
return this.attr.type;
}
getObject() {
getObject(url: URL) {
if (this.attr.object instanceof Article) {
return this.attr.object.getJSONLD(url);
}
return this.attr.object;
}
@ -54,6 +58,9 @@ export class Activity extends Entity<ActivityData> {
}
get objectId() {
if (this.attr.object instanceof Article) {
return this.attr.object.objectId;
}
return this.attr.object.id;
}
@ -62,7 +69,7 @@ export class Activity extends Entity<ActivityData> {
}
getJSONLD(url: URL): ActivityPub.Activity {
const object = this.getObject();
const object = this.getObject(url);
return {
'@context': 'https://www.w3.org/ns/activitystreams',
id: this.activityId?.getValue(url) || null,

View File

@ -157,10 +157,7 @@ export class Actor extends Entity<ActorData> {
to: this.followersCollectionId,
type: 'Create',
actor: this.actorId,
object: {
id: article.objectId,
type: 'Article'
}
object: article
});
this.doActivity(activity);
}