Node.js based forum software built for the modern web
feat: #8960, update view count after merge
Barış Soner Uşaklı14bb0a446917
diff --git a/src/topics/merge.js b/src/topics/merge.jsindex b3f5718422..2688ef69fc 100644--- a/src/topics/merge.js+++ b/src/topics/merge.js@@ -32,7 +32,14 @@ module.exports = function (Topics) {});});- plugins.hooks.fire('action:topic.merge', { uid: uid, tids: tids, mergeIntoTid: mergeIntoTid, otherTids: otherTids });+ await updateViewCount(mergeIntoTid, tids);++ plugins.hooks.fire('action:topic.merge', {+ uid: uid,+ tids: tids,+ mergeIntoTid: mergeIntoTid,+ otherTids: otherTids,+ });return mergeIntoTid;};@@ -46,6 +53,14 @@ module.exports = function (Topics) {return tid;}+ async function updateViewCount(mergeIntoTid, tids) {+ const topicData = await Topics.getTopicsFields(tids, ['viewcount']);+ const totalViewCount = topicData.reduce(+ (count, topic) => count + parseInt(topic.viewcount, 10), 0+ );+ await Topics.setTopicField(mergeIntoTid, 'viewcount', totalViewCount);+ }+function findOldestTopic(tids) {return Math.min.apply(null, tids);}