Node.js based forum software built for the modern web
fix: closes #13624, update post fields before schedule code
Barış Soner Uşaklı9d4a9b83ccab
diff --git a/src/posts/edit.js b/src/posts/edit.jsindex b18bf99078..0b8b6ff009 100644--- a/src/posts/edit.js+++ b/src/posts/edit.js@@ -49,12 +49,14 @@ module.exports = function (Posts) {uid: data.uid,});+ // needs to be before editMainPost, otherwise scheduled topics use wrong timestamp+ await Posts.setPostFields(data.pid, result.post);+const [editor, topic] = await Promise.all([user.getUserFields(data.uid, ['username', 'userslug']),editMainPost(data, postData, topicData),]);- await Posts.setPostFields(data.pid, result.post);const contentChanged = ((data.sourceContent || data.content) !== oldContent) ||topic.renamed ||topic.tagsupdated;diff --git a/test/topics.js b/test/topics.jsindex bc92bbff09..eaae7d76c7 100644--- a/test/topics.js+++ b/test/topics.js@@ -2506,6 +2506,35 @@ describe('Topic\'s', () => {const score = await db.sortedSetScore('topics:scheduled', topicData.tid);assert(!score);});++ it('should properly update timestamp in cid:<cid>:pids after editing and posting immediately', async () => {+ const scheduleTimestamp = Date.now() + (86400000 * 365);+ const result = await topics.post({+ cid: categoryObj.cid,+ title: 'testing cid:<cid>:pids',+ content: 'some content here',+ uid: adminUid,+ timestamp: scheduleTimestamp,+ });+ const { mainPid } = result.topicData;++ assert.strictEqual(+ await db.isSortedSetMember(`cid:${categoryObj.cid}:pids`, mainPid),+ false,+ );++ // edit main post and publish+ await posts.edit({+ uid: adminUid,+ pid: mainPid,+ content: 'some content here - edited',+ timestamp: Date.now(),+ });++ // the score in cid:<cid>:pids should be less than Date.now()+ const score = await db.sortedSetScore(`cid:${categoryObj.cid}:pids`, mainPid);+ assert(score < Date.now(), 'Post in cid:<cid>:pids has wrong score, it should not be in the future');+ });});});