Isn't this how stack overflow works as well? The vote count is for the question itself. I took a look at that code and it wasn't trivial to implement this without a new function so I added that here: https://github.com/NodeBB/NodeBB/pull/11579.
If anyone wants to build it as a plugin it can be done using the function from the above pull request. I will leave the code required here.
In plugin.json add this hook, it gets fired whenever a list of topics is loaded.
{ "hook": "filter:topics.get", "method": "filterTopicsGet" }Now the code that will recalculate the vote count from the posts of the topics:
const db = require.main.require('./src/database'); library.filterTopicsGet = async (hookData) => { const voteData = await db.getSortedSetsMembersWithScores( hookData.topics.map(t => `tid:${t.tid}:posts:votes`) ); hookData.topics.forEach((t, index) => { if (t) { const allvotes = voteData[index].reduce((acc, cur) => acc + cur.score, 0); t.votes += allvotes; } }); return hookData; };Now the vote displayed on the topic list will be the total number of votes from all the posts in the topic.