feat: topic and category S2S get responses

This commit is contained in:
Julian Lam
2024-02-06 11:04:08 -05:00
parent 25f0d48432
commit a461e5dd41
4 changed files with 22 additions and 8 deletions

View File

@@ -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);

View File

@@ -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,

View File

@@ -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) {

View File

@@ -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);