From acd1630b9f4e3e53c2f6a1a7f0dade117d78e25e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 13 Jun 2024 14:02:26 -0400 Subject: [PATCH] fix: move logic to move topic on note assertion earlier in the flow so it actually runs --- src/activitypub/notes.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index 228bde68d3..5d8e44b079 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -51,6 +51,15 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { let { pid: mainPid, tid, uid: authorId, timestamp, name, content } = mainPost; const hasTid = !!tid; + // Update category if currently uncategorized + if (hasTid) { + const cid = await topics.getTopicField(tid, 'cid'); + if (options.cid && cid === -1) { + // Move topic + await topics.tools.move(tid, { cid: options.cid, uid: 'system' }); + } + } + const members = await db.isSortedSetMembers(`tid:${tid}:posts`, chain.slice(0, -1).map(p => p.pid)); members.push(await posts.exists(mainPid)); if (tid && members.every(Boolean)) { @@ -63,12 +72,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { let cid; let title; if (hasTid) { - ({ cid, mainPid } = await topics.getTopicFields(tid, ['tid', 'cid', 'mainPid'])); - - if (options.cid && cid === -1) { - // Move topic - await topics.tools.move(tid, { cid: options.cid, uid: 'system' }); - } + mainPid = await topics.getTopicField(tid, 'mainPid'); } else { // mainPid ok to leave as-is cid = options.cid || -1;