feat: #8960, update view count after merge

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 4317cdea34
commit 14bb0a4469

@ -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);
}

Loading…
Cancel
Save