Node.js based forum software built for the modern web
refactor: acceptable types in context.js to index.js, allow searching for remote topis by topic url
Julian Lamd644c0f41c42
diff --git a/src/activitypub/contexts.js b/src/activitypub/contexts.jsindex 08546bb9e6..7ca954e097 100644--- a/src/activitypub/contexts.js+++ b/src/activitypub/contexts.js@@ -7,8 +7,6 @@ const topics = require('../topics');const activitypub = module.parent.exports;const Contexts = module.exports;-const acceptableTypes = ['Collection', 'CollectionPage', 'OrderedCollection', 'OrderedCollectionPage'];-Contexts.get = async (uid, id) => {let context;let type;@@ -28,7 +26,7 @@ Contexts.get = async (uid, id) => {try {({ id, type, context } = await activitypub.get('uid', uid, id, { headers }));- if (acceptableTypes.includes(type)) { // is context+ if (activitypub._constants.acceptable.contextTypes.has(type)) { // is contextactivitypub.helpers.log(`[activitypub/context] ${id} is the context.`);return { context: id };} else if (!context) {@@ -48,7 +46,7 @@ Contexts.get = async (uid, id) => {return false;}- if (acceptableTypes.includes(type)) {+ if (activitypub._constants.acceptable.contextTypes.has(type)) {return { context };}@@ -62,7 +60,7 @@ Contexts.getItems = async (uid, id, options) => {activitypub.helpers.log(`[activitypub/context] Retrieving context ${id}`);let { type, items, orderedItems, first, next } = await activitypub.get('uid', uid, id);- if (!acceptableTypes.includes(type)) {+ if (!activitypub._constants.acceptable.contextTypes.has(type)) {return false;}diff --git a/src/activitypub/index.js b/src/activitypub/index.jsindex 4a6d95b48b..1884eb76ef 100644--- a/src/activitypub/index.js+++ b/src/activitypub/index.js@@ -44,6 +44,7 @@ ActivityPub._constants = Object.freeze({acceptedProtocols: ['https', ...(process.env.CI === 'true' ? ['http'] : [])],acceptable: {customFields: new Set(['PropertyValue', 'Link', 'Note']),+ contextTypes: new Set(['Collection', 'CollectionPage', 'OrderedCollection', 'OrderedCollectionPage']),},});ActivityPub._cache = requestCache;diff --git a/src/search.js b/src/search.jsindex 1609bea31f..8e9d947dae 100644--- a/src/search.js+++ b/src/search.js@@ -173,7 +173,7 @@ async function fetchRemoteObject(data) {} else if (activitypub._constants.acceptableActorTypes.has(type)) {data.searchIn = 'users';return await user.search(data);- } else if (type === 'Conversation') {+ } else if (activitypub._constants.acceptable.contextTypes.has(type)) {({ tid } = await activitypub.notes.assert(uid, id));id = await topics.getTopicField(tid, 'mainPid');}