Skip to content

Commit

Permalink
Added missing attributedTo to Articles
Browse files Browse the repository at this point in the history
refs https://linear.app/tryghost/issue/AP-427

This was missing and made it difficult for implementations to Like or Announce
our articles, because they needed a reference to the Create activity to get the
authors inbox
  • Loading branch information
allouis committed Sep 24, 2024
1 parent 9e9321f commit 7f8bf55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions features/create-article-from-post.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Feature: Deliver Create(Article) activities when a post.published webhook is rec
When it is sent to the webhook endpoint
Then the request is accepted
Then a "Create(Article)" activity is in the Outbox
And the found "Create(Article)" has property "object.attributedTo"
14 changes: 14 additions & 0 deletions features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,23 @@ Then('a {string} activity is in the Outbox', async function (string) {
const found = outbox.orderedItems.find((item) => {
return item.type === activity && item.object?.type === object
});
if (!this.found) {
this.found = {};
}
this.found[string] = found;
assert.ok(found);
});

Then('the found {string} has property {string}', function (name, prop) {
const found = this.found[name];

const property = prop.split('.').reduce(function (thing, key) {
return thing?.[key];
}, found);

assert.ok(property);
});

Then('{string} is in our Inbox', async function (activityName) {
const response = await fetch('http://activitypub-testing:8083/.ghost/activitypub/inbox/index', {
headers: {
Expand Down
6 changes: 4 additions & 2 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const PostSchema = z.object({

type Post = z.infer<typeof PostSchema>

async function postToArticle(ctx: RequestContext<ContextData>, post: Post) {
async function postToArticle(ctx: RequestContext<ContextData>, post: Post, author: Actor | null) {
if (!post) {
return {
article: null,
Expand All @@ -66,6 +66,7 @@ async function postToArticle(ctx: RequestContext<ContextData>, post: Post) {
});
const article = new Article({
id: ctx.getObjectUri(Article, { id: post.uuid }),
attribution: author,
name: post.title,
content: post.html,
image: toURL(post.feature_image),
Expand Down Expand Up @@ -366,12 +367,13 @@ export async function postPublishedWebhook(
db: ctx.get('db'),
globaldb: ctx.get('globaldb'),
});
const actor = await apCtx.getActor(ACTOR_DEFAULT_HANDLE);
const { article, preview } = await postToArticle(
apCtx,
data.post.current,
actor
);
if (article) {
const actor = await apCtx.getActor(ACTOR_DEFAULT_HANDLE);
const create = new Create({
actor,
object: article,
Expand Down

0 comments on commit 7f8bf55

Please sign in to comment.