diff --git a/src/activitypub/index.js b/src/activitypub/index.js index b3b68c5057..0c7fb0b777 100644 --- a/src/activitypub/index.js +++ b/src/activitypub/index.js @@ -237,10 +237,3 @@ ActivityPub.send = async (type, id, targets, payload) => { } })); }; - -setTimeout(async () => { - await ActivityPub.send('uid', 1, 'https://localhost/category/1', { - type: 'Follow', - object: 'https://localhost/category/1', - }); -}, 2000); diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index 4074bc57f7..5626f84869 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -232,6 +232,7 @@ Mocks.note = async (post) => { published, url: id, attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`, + audience: `${nconf.get('url')}/topic/${post.topic.slug}`, sensitive: false, // todo summary: null, name, diff --git a/src/controllers/activitypub/actors.js b/src/controllers/activitypub/actors.js index b14b46c380..2d7e1cb751 100644 --- a/src/controllers/activitypub/actors.js +++ b/src/controllers/activitypub/actors.js @@ -4,6 +4,7 @@ const nconf = require('nconf'); const meta = require('../../meta'); const posts = require('../../posts'); +const topics = require('../../topics'); const categories = require('../../categories'); const activitypub = require('../../activitypub'); @@ -58,6 +59,23 @@ Actors.note = async function (req, res, next) { res.status(200).json(payload); }; +Actors.topic = async function (req, res, next) { + // When queried, a topic more or less returns the main pid's note representation + const { mainPid, slug } = await topics.getTopicFields(req.params.tid, ['mainPid', 'slug']); + const post = (await posts.getPostSummaryByPids([mainPid], req.uid, { stripTags: false })).pop(); + if (!post) { + return next('route'); + } + + const payload = await activitypub.mocks.note(post); + payload.id = `${nconf.get('url')}/topic/${req.params.tid}`; + payload.type = 'Page'; + payload.url = `${nconf.get('url')}/topic/${slug}`; + payload.audience = `${nconf.get('url')}/category/${post.category.slug}`; + + res.status(200).json(payload); +}; + Actors.category = async function (req, res, next) { const exists = await categories.exists(req.params.cid); if (!exists) { diff --git a/src/routes/activitypub.js b/src/routes/activitypub.js index 68747c1d1e..7c50b782ee 100644 --- a/src/routes/activitypub.js +++ b/src/routes/activitypub.js @@ -31,7 +31,9 @@ module.exports = function (app, middleware, controllers) { app.get('/post/:pid', [...middlewares, middleware.assert.post], controllers.activitypub.actors.note); - app.get('/category/:cid', [...middlewares, middleware.assert.category], controllers.activitypub.actors.category); + app.get('/topic/:tid/:slug?', [...middlewares, middleware.assert.topic], controllers.activitypub.actors.topic); + + app.get('/category/:cid/:slug?', [...middlewares, middleware.assert.category], controllers.activitypub.actors.category); app.get('/category/:cid/inbox', [...middlewares, middleware.assert.category], controllers.activitypub.getInbox); app.post('/category/:cid/inbox', [...middlewares, middleware.assert.category, middleware.activitypub.validate], controllers.activitypub.postInbox); app.get('/category/:cid/outbox', [...middlewares, middleware.assert.category], controllers.activitypub.getCategoryOutbox);