mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +01:00
feat: #8960, update view count after merge
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user