diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index cdbb6f5131..2fb2810a6c 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -286,6 +286,12 @@ inbox.announce = async (req) => { break; } + case object.type === 'Update': { + req.body = object; + await inbox.update(req); + break; + } + case activitypub._constants.acceptedPostTypes.includes(object.type): { if (String(object.id).startsWith(nconf.get('url'))) { // Local object const { type, id } = await activitypub.helpers.resolveLocalId(object.id); diff --git a/test/activitypub/helpers.js b/test/activitypub/helpers.js index 4d168d01c7..e4c3a4d689 100644 --- a/test/activitypub/helpers.js +++ b/test/activitypub/helpers.js @@ -176,3 +176,26 @@ Helpers.mocks.announce = (override = {}) => { return { activity }; }; +Helpers.mocks.update = (override = {}) => { + let actor = override.actor; + let object = override.object; + if (!actor) { + ({ id: actor } = Helpers.mocks.person()); + } + if (!object) { + ({ id: object } = Helpers.mocks.note()); + } + + const activity = { + '@context': 'https://www.w3.org/ns/activitystreams', + id: `${Helpers.mocks._baseUrl}/update/${encodeURIComponent(object.id || object)}`, + type: 'Update', + to: [activitypub._constants.publicAddress], + cc: [`${actor}/followers`], + actor, + object, + }; + + return { activity }; +}; + diff --git a/test/activitypub/notes.js b/test/activitypub/notes.js index 0e2abaafb7..9b4aaf8653 100644 --- a/test/activitypub/notes.js +++ b/test/activitypub/notes.js @@ -411,7 +411,7 @@ describe('Notes', () => { }); }); - describe.only('Inbox handling', () => { + describe('Inbox handling', () => { describe('helper self-check', () => { it('should generate a Like activity', () => { const object = utils.generateUUID(); @@ -544,6 +544,22 @@ describe('Notes', () => { assert.strictEqual(upvotes, 1); }); }); + + describe('(Update)', () => { + it('should update a note\'s content', async () => { + const { id: actor } = helpers.mocks.person(); + const { id, note } = helpers.mocks.note({ attributedTo: actor }); + await activitypub.notes.assert(0, [id], { skipChecks: true }); + note.content = utils.generateUUID(); + const { activity: update } = helpers.mocks.update({ object: note }); + const { activity } = helpers.mocks.announce({ object: update }); + + await activitypub.inbox.announce({ body: activity }); + + const content = await posts.getPostField(id, 'content'); + assert.strictEqual(content, note.content); + }); + }); }); });