fix: move logic to move topic on note assertion earlier in the flow so it actually runs

This commit is contained in:
Julian Lam
2024-06-13 14:02:26 -04:00
parent badb7e2c05
commit acd1630b9f

View File

@@ -51,6 +51,15 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
let { pid: mainPid, tid, uid: authorId, timestamp, name, content } = mainPost; let { pid: mainPid, tid, uid: authorId, timestamp, name, content } = mainPost;
const hasTid = !!tid; 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)); const members = await db.isSortedSetMembers(`tid:${tid}:posts`, chain.slice(0, -1).map(p => p.pid));
members.push(await posts.exists(mainPid)); members.push(await posts.exists(mainPid));
if (tid && members.every(Boolean)) { if (tid && members.every(Boolean)) {
@@ -63,12 +72,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
let cid; let cid;
let title; let title;
if (hasTid) { if (hasTid) {
({ cid, mainPid } = await topics.getTopicFields(tid, ['tid', 'cid', 'mainPid'])); mainPid = await topics.getTopicField(tid, 'mainPid');
if (options.cid && cid === -1) {
// Move topic
await topics.tools.move(tid, { cid: options.cid, uid: 'system' });
}
} else { } else {
// mainPid ok to leave as-is // mainPid ok to leave as-is
cid = options.cid || -1; cid = options.cid || -1;