mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 11:55:01 +03:00
Included full Object in Activities
ref https://linear.app/tryghost/issue/MOM-127 This will save us on network fetches when trying to hydrate the inbox, instead we can include all of the data we want/need. I had to improve the typing a bit here to work properly which meant ensuring that we have a `type` property.
This commit is contained in:
parent
d15858e16a
commit
8842dc2312
@ -6,8 +6,12 @@ type ActivityData = {
|
||||
activity: URI | null;
|
||||
type: ActivityPub.ActivityType;
|
||||
actor: URI;
|
||||
object: {
|
||||
id: URI;
|
||||
type: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
object: {id: URI, [x: string]: any};
|
||||
[x: string]: any;
|
||||
};
|
||||
to: URI | null;
|
||||
}
|
||||
|
||||
@ -58,6 +62,7 @@ export class Activity extends Entity<ActivityData> {
|
||||
}
|
||||
|
||||
getJSONLD(url: URL): ActivityPub.Activity {
|
||||
const object = this.getObject();
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: this.activityId?.getValue(url) || null,
|
||||
@ -67,7 +72,10 @@ export class Activity extends Entity<ActivityData> {
|
||||
id: this.actorId.getValue(url),
|
||||
username: `@index@${this.actorId.hostname}`
|
||||
},
|
||||
object: this.objectId.getValue(url),
|
||||
object: {
|
||||
...object,
|
||||
id: this.objectId.getValue(url)
|
||||
},
|
||||
to: this.attr.to?.getValue(url) || null
|
||||
};
|
||||
}
|
||||
@ -81,7 +89,10 @@ export class Activity extends Entity<ActivityData> {
|
||||
activity: 'id' in json ? getURI(json.id) : null,
|
||||
type: parsed.type as ActivityPub.ActivityType,
|
||||
actor: getURI(parsed.actor),
|
||||
object: {id: getURI(parsed.object)},
|
||||
object: {
|
||||
id: getURI(parsed.object),
|
||||
type: 'Unknown'
|
||||
},
|
||||
to: 'to' in json ? getURI(json.to) : null
|
||||
});
|
||||
}
|
||||
|
@ -125,7 +125,10 @@ describe('Actor', function () {
|
||||
activity: new URI(`https://activitypub.server/activity`),
|
||||
type: 'Follow',
|
||||
actor: newFollower,
|
||||
object: {id: actor.actorId},
|
||||
object: {
|
||||
id: actor.actorId,
|
||||
type: 'Person'
|
||||
},
|
||||
to: actor.actorId
|
||||
});
|
||||
|
||||
@ -143,7 +146,10 @@ describe('Actor', function () {
|
||||
activity: null,
|
||||
type: 'Follow',
|
||||
actor: newFollower,
|
||||
object: {id: actor.actorId},
|
||||
object: {
|
||||
id: actor.actorId,
|
||||
type: 'Person'
|
||||
},
|
||||
to: actor.actorId
|
||||
});
|
||||
|
||||
@ -167,7 +173,8 @@ describe('Actor', function () {
|
||||
type: 'Accept',
|
||||
actor: newFollower,
|
||||
object: {
|
||||
id: newFollower
|
||||
id: newFollower,
|
||||
type: 'Person'
|
||||
},
|
||||
to: actor.actorId
|
||||
});
|
||||
|
@ -110,7 +110,10 @@ export class Actor extends Entity<ActorData> {
|
||||
activity: new URI(`activity/${(new ObjectID).toHexString()}`),
|
||||
type: 'Follow',
|
||||
actor: this.actorId,
|
||||
object: actor,
|
||||
object: {
|
||||
...actor,
|
||||
type: 'Person'
|
||||
},
|
||||
to: actor.id
|
||||
});
|
||||
this.doActivity(activity);
|
||||
@ -126,7 +129,10 @@ export class Actor extends Entity<ActorData> {
|
||||
type: 'Accept',
|
||||
to: activity.actorId,
|
||||
actor: this.actorId,
|
||||
object: {id: activity.activityId}
|
||||
object: {
|
||||
id: activity.activityId,
|
||||
type: 'Follow'
|
||||
}
|
||||
});
|
||||
this.doActivity(accept);
|
||||
}
|
||||
@ -151,7 +157,10 @@ export class Actor extends Entity<ActorData> {
|
||||
to: this.followersCollectionId,
|
||||
type: 'Create',
|
||||
actor: this.actorId,
|
||||
object: {id: article.objectId}
|
||||
object: {
|
||||
id: article.objectId,
|
||||
type: 'Article'
|
||||
}
|
||||
});
|
||||
this.doActivity(activity);
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ describe('InboxService', function () {
|
||||
type: 'Follow',
|
||||
activity: null,
|
||||
object: {
|
||||
type: 'Application',
|
||||
id: new URI('https://whatever.com')
|
||||
},
|
||||
actor: new URI('https://blak.com'),
|
||||
@ -59,6 +60,7 @@ describe('InboxService', function () {
|
||||
type: 'Follow',
|
||||
activity: null,
|
||||
object: {
|
||||
type: 'Person',
|
||||
id: new URI('https://whatever.com')
|
||||
},
|
||||
actor: new URI('https://blak.com'),
|
||||
|
@ -27,6 +27,7 @@ describe('TheWorld', function () {
|
||||
activity: null,
|
||||
actor: actor.actorId,
|
||||
object: {
|
||||
type: 'Person',
|
||||
id: toFollow
|
||||
},
|
||||
to: toFollow
|
||||
|
@ -30,6 +30,7 @@ describe('ActivityListener', function () {
|
||||
activity: null,
|
||||
actor: actor.actorId,
|
||||
object: {
|
||||
type: 'Person',
|
||||
id: toFollow
|
||||
},
|
||||
to: toFollow
|
||||
|
Loading…
Reference in New Issue
Block a user