From 9997189aeae75784e43507e0c54b2b7e017a05a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 18 Feb 2025 12:06:02 -0500 Subject: [PATCH 1/4] feat: remove activities older than a week --- src/activitypub/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/activitypub/index.js b/src/activitypub/index.js index 3eec80eae1..1ab36c3773 100644 --- a/src/activitypub/index.js +++ b/src/activitypub/index.js @@ -61,6 +61,7 @@ ActivityPub.startJobs = () => { new CronJob('0 0 * * *', async () => { try { await ActivityPub.notes.prune(); + await db.sortedSetsRemoveRangeByScore(['activities:datetime'], '-inf', Date.now() - 604800000); } catch (err) { winston.error(err.stack); } From 4bc0031f587f62f810a5af0fdb241f413bd3821f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 18 Feb 2025 13:07:11 -0500 Subject: [PATCH 2/4] chore: add test helper to activitypub file --- src/activitypub/helpers.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index dd0b0c05ff..5a50e2e8ed 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -28,6 +28,16 @@ const sha256 = payload => crypto.createHash('sha256').update(payload).digest('he const Helpers = module.exports; +Helpers._test = (method, args) => { + // because I am lazy and I probably wrote some variant of this below code 1000 times already + setTimeout(async () => { + console.log(await method.apply(method, args)); + }, 2500); +}; +// process.nextTick(() => { +// Helpers._test(activitypub.notes.assert, [1, `https://`]); +// }); + let _lastLog; Helpers.log = (message) => { if (!message) { From de6e63bbd7e0be5459d8541faec280312b1532b9 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 18 Feb 2025 13:33:11 -0500 Subject: [PATCH 3/4] fix: add back chronological sorting of asserted notes --- src/activitypub/notes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index f40d4bdb68..2b6a0fceaa 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -71,7 +71,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { } // Reorder chain items by timestamp - // chain = chain.sort((a, b) => a.timestamp - b.timestamp); + chain = chain.sort((a, b) => a.timestamp - b.timestamp); const mainPost = chain[0]; let { pid: mainPid, tid, uid: authorId, timestamp, name, content, sourceContent, _activitypub } = mainPost; From 6245e33d6e1702c740d3f3b835d5a8a03fbb073d Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 18 Feb 2025 13:34:17 -0500 Subject: [PATCH 4/4] 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