mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: acceptable types in context.js to index.js, allow searching for remote topis by topic url
This commit is contained in:
@@ -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 context
|
||||
activitypub.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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user