diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index e0a76486b8..5299898af8 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -11,6 +11,7 @@ const crypto = require('crypto'); const meta = require('../meta'); const posts = require('../posts'); const categories = require('../categories'); +const messaging = require('../messaging'); const request = require('../request'); const db = require('../database'); const ttl = require('../cache/ttl'); @@ -263,6 +264,7 @@ Helpers.resolveObjects = async (ids) => { } return activitypub.mocks.actors.user(resolvedId); } + case 'post': { const post = (await posts.getPostSummaryByPids( [resolvedId], @@ -277,12 +279,23 @@ Helpers.resolveObjects = async (ids) => { } return activitypub.mocks.notes.public(post); } + case 'category': { if (!await categories.exists(resolvedId)) { throw new Error('[[error:activitypub.invalid-id]]'); } return activitypub.mocks.actors.category(resolvedId); } + + case 'message': { + if (!await messaging.messageExists(resolvedId)) { + throw new Error('[[error:activitypub.invalid-id]]'); + } + const messageObj = await messaging.getMessageFields(resolvedId, []); + messageObj.content = await messaging.parse(messageObj.content, messageObj.fromuid, 0, messageObj.roomId, false); + return activitypub.mocks.notes.private({ messageObj }); + } + // if the type is not recognized, assume it's not a local ID and fetch the object from its origin default: { return activitypub.get('uid', 0, id); diff --git a/src/middleware/activitypub.js b/src/middleware/activitypub.js index 8913339ea4..10ab302369 100644 --- a/src/middleware/activitypub.js +++ b/src/middleware/activitypub.js @@ -134,6 +134,7 @@ middleware.resolveObjects = async function (req, res, next) { return res.sendStatus(424); } } + next(); };