From f800c7e20580725e3de0d699f972db9a93d82ef1 Mon Sep 17 00:00:00 2001 From: fatchan Date: Thu, 9 May 2019 05:12:48 +0000 Subject: [PATCH] refresh page that thread preview shown on when new sage post is made --- models/forms/make-post.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/models/forms/make-post.js b/models/forms/make-post.js index 02bf0a66..29f110e6 100644 --- a/models/forms/make-post.js +++ b/models/forms/make-post.js @@ -234,11 +234,14 @@ module.exports = async (req, res, next, numFiles) => { if (data.thread) { //refresh the thread itself removePromises.push(remove(`${uploadDirectory}html/${req.params.board}/thread/${req.body.thread}.html`)); + //refersh pages + const numThreadsBefore = await Posts.getBeforeCount(req.params.board, thread); + const pagesToRemove = Math.ceil(numThreadsBefore/10) || 1; + //refresh the page that the thread is on + removePromises.push(remove(`${uploadDirectory}html/${req.params.board}/${pagesToRemove == 1 ? 'index' : pagesToRemove}.html`)); if (!data.sage) { - //bumping a thread, so delete all pages above it - const numThreadsBefore = await Posts.getBeforeCount(req.params.board, thread); - const pagesToRemove = Math.ceil(numThreadsBefore/10) || 1; //|| 1, so we always refresh first page incase this is the top thread nothing will be before it - for (let i = 1; i <= pagesToRemove; i++) { + //if not saged, it will bump so we should refresh any pages above it as well + for (let i = pagesToRemove-1; i >= 1; i--) { removePromises.push(remove(`${uploadDirectory}html/${req.params.board}/${i == 1 ? 'index' : i}.html`)); } }