mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
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.
This commit is contained in:
parent
c4091fc000
commit
5e0f1a1732
2 changed files with 19 additions and 7 deletions
|
@ -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<ActivityData> {
|
|||
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<ActivityData> {
|
|||
|
||||
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)
|
||||
|
|
|
@ -156,7 +156,7 @@ export class Actor extends Entity<ActorData> {
|
|||
activity: new URI(`activity/${new ObjectID().toHexString()}`),
|
||||
to: this.followersCollectionId,
|
||||
type: 'Create',
|
||||
actor: this.actorId,
|
||||
actor: this,
|
||||
object: article
|
||||
});
|
||||
this.doActivity(activity);
|
||||
|
|
Loading…
Add table
Reference in a new issue