mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +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;
|
return mergeIntoTid;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -46,6 +53,14 @@ module.exports = function (Topics) {
|
|||||||
return tid;
|
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) {
|
function findOldestTopic(tids) {
|
||||||
return Math.min.apply(null, tids);
|
return Math.min.apply(null, tids);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user