From 6245e33d6e1702c740d3f3b835d5a8a03fbb073d Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 18 Feb 2025 13:34:17 -0500 Subject: [PATCH] fix: #13179, fix context resolution failure bug with frequency --- src/activitypub/contexts.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/activitypub/contexts.js b/src/activitypub/contexts.js index 12dcae1059..b6cb1890e6 100644 --- a/src/activitypub/contexts.js +++ b/src/activitypub/contexts.js @@ -55,8 +55,20 @@ Contexts.getItems = async (uid, id, options) => { options.root = true; } - activitypub.helpers.log(`[activitypub/context] Retrieving context ${id}`); - let { type, items, orderedItems, first, next } = await activitypub.get('uid', uid, id); + // Page object instead of id + let object; + if (!id && options.object) { + object = options.object; + } else { + activitypub.helpers.log(`[activitypub/context] Retrieving context/page ${id}`); + try { + object = await activitypub.get('uid', uid, id); + } catch (e) { + return false; + } + } + let { type, items, orderedItems, first, next } = object; + if (!acceptableTypes.includes(type)) { return false; } @@ -84,14 +96,18 @@ Contexts.getItems = async (uid, id, options) => { if (next) { activitypub.helpers.log('[activitypub/context] Fetching next page...'); + const isUrl = activitypub.helpers.isUri(next); Array - .from(await Contexts.getItems(uid, next, { + .from(await Contexts.getItems(uid, isUrl && next, { ...options, root: false, + object: !isUrl && next, })) .forEach((item) => { chain.add(item); }); + + return chain; } // Handle special case where originating object is not actually part of the context collection