refactor: acceptable types in context.js to index.js, allow searching for remote topis by topic url

This commit is contained in:
Julian Lam
2025-01-30 16:41:52 -05:00
parent 54bc54e176
commit d644c0f41c
3 changed files with 5 additions and 6 deletions

View File

@@ -7,8 +7,6 @@ const topics = require('../topics');
const activitypub = module.parent.exports; const activitypub = module.parent.exports;
const Contexts = module.exports; const Contexts = module.exports;
const acceptableTypes = ['Collection', 'CollectionPage', 'OrderedCollection', 'OrderedCollectionPage'];
Contexts.get = async (uid, id) => { Contexts.get = async (uid, id) => {
let context; let context;
let type; let type;
@@ -28,7 +26,7 @@ Contexts.get = async (uid, id) => {
try { try {
({ id, type, context } = await activitypub.get('uid', uid, id, { headers })); ({ id, type, context } = await activitypub.get('uid', uid, id, { headers }));
if (acceptableTypes.includes(type)) { // is context if (activitypub._constants.acceptable.contextTypes.has(type)) { // is context
activitypub.helpers.log(`[activitypub/context] ${id} is the context.`); activitypub.helpers.log(`[activitypub/context] ${id} is the context.`);
return { context: id }; return { context: id };
} else if (!context) { } else if (!context) {
@@ -48,7 +46,7 @@ Contexts.get = async (uid, id) => {
return false; return false;
} }
if (acceptableTypes.includes(type)) { if (activitypub._constants.acceptable.contextTypes.has(type)) {
return { context }; return { context };
} }
@@ -62,7 +60,7 @@ Contexts.getItems = async (uid, id, options) => {
activitypub.helpers.log(`[activitypub/context] Retrieving context ${id}`); activitypub.helpers.log(`[activitypub/context] Retrieving context ${id}`);
let { type, items, orderedItems, first, next } = await activitypub.get('uid', uid, 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; return false;
} }

View File

@@ -44,6 +44,7 @@ ActivityPub._constants = Object.freeze({
acceptedProtocols: ['https', ...(process.env.CI === 'true' ? ['http'] : [])], acceptedProtocols: ['https', ...(process.env.CI === 'true' ? ['http'] : [])],
acceptable: { acceptable: {
customFields: new Set(['PropertyValue', 'Link', 'Note']), customFields: new Set(['PropertyValue', 'Link', 'Note']),
contextTypes: new Set(['Collection', 'CollectionPage', 'OrderedCollection', 'OrderedCollectionPage']),
}, },
}); });
ActivityPub._cache = requestCache; ActivityPub._cache = requestCache;

View File

@@ -173,7 +173,7 @@ async function fetchRemoteObject(data) {
} else if (activitypub._constants.acceptableActorTypes.has(type)) { } else if (activitypub._constants.acceptableActorTypes.has(type)) {
data.searchIn = 'users'; data.searchIn = 'users';
return await user.search(data); return await user.search(data);
} else if (type === 'Conversation') { } else if (activitypub._constants.acceptable.contextTypes.has(type)) {
({ tid } = await activitypub.notes.assert(uid, id)); ({ tid } = await activitypub.notes.assert(uid, id));
id = await topics.getTopicField(tid, 'mainPid'); id = await topics.getTopicField(tid, 'mainPid');
} }