Skip to content

Node.js based forum software built for the modern web

fix: #13076, allow pulling in of topics by their topic URL fix: reapply fixes that were part of since-reverted 4fd7a9dc59b65e8654d704c493f2254793e8d6a9

Julian Lamc6e6ab438b08
diff --git a/src/activitypub/contexts.js b/src/activitypub/contexts.js
index 12dcae1059..08546bb9e6 100644
--- a/src/activitypub/contexts.js
+++ b/src/activitypub/contexts.js
@@ -27,11 +27,16 @@ Contexts.get = async (uid, id) => {
}
try {
- ({ context } = await activitypub.get('uid', uid, id, { headers }));
- if (!context) {
+ ({ id, type, context } = await activitypub.get('uid', uid, id, { headers }));
+ if (acceptableTypes.includes(type)) { // is context
+ activitypub.helpers.log(`[activitypub/context] ${id} is the context.`);
+ return { context: id };
+ } else if (!context) {
activitypub.helpers.log(`[activitypub/context] ${id} contains no context.`);
return false;
}
+
+ // context provided; try to resolve it.
({ type } = await activitypub.get('uid', uid, context));
} catch (e) {
if (e.code === 'ap_get_304') {
@@ -98,9 +103,13 @@ Contexts.getItems = async (uid, id, options) => {
const inputId = activitypub.helpers.isUri(options.input) ? options.input : options.input.id;
const inCollection = Array.from(chain).map(p => p.pid).includes(inputId);
if (!inCollection) {
- chain.add(activitypub.helpers.isUri(options.input) ?
+ const item = activitypub.helpers.isUri(options.input) ?
await parseString(uid, options.input) :
- await parseItem(uid, options.input));
+ await parseItem(uid, options.input);
+
+ if (item) {
+ chain.add(item);
+ }
}
return chain;
diff --git a/src/routes/activitypub.js b/src/routes/activitypub.js
index 8993cb8875..b6a516b481 100644
--- a/src/routes/activitypub.js
+++ b/src/routes/activitypub.js
@@ -42,11 +42,11 @@ module.exports = function (app, middleware, controllers) {
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', [...inboxMiddlewares, middleware.assert.category, ...inboxMiddlewares], controllers.activitypub.postInbox);
app.get('/category/:cid/outbox', [...middlewares, middleware.assert.category], controllers.activitypub.getCategoryOutbox);
app.post('/category/:cid/outbox', [...middlewares, middleware.assert.category], controllers.activitypub.postOutbox);
+ app.get('/category/:cid/:slug?', [...middlewares, middleware.assert.category], controllers.activitypub.actors.category);
app.get('/message/:mid', [...middlewares, middleware.assert.message], controllers.activitypub.actors.message);
};