Total vote count on topic list
-
@baris can we have another option to calculate the vote numbers of a topic in ACP? So each admin can decide for their forum. I prefer a calculation where all of the positive and negative votes in the thread are considered. Sometimes the first post may not be the key post, but rather it is a question. So it looks 0 vote, although the topic itself is very useful.
-
@crazycells I agree with this. I too have a number of posts on my forum where the initial didn't have many upvotes but subsequent ones do.
-
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.
-
J julian moved this topic from Feature Requests on
-
thanks @oplik0 and @baris for the plugin...
GitHub - oplik0/nodebb-plugin-total-vote-count: Calculate vote totals based on all posts in topics and not just the inital post
Calculate vote totals based on all posts in topics and not just the inital post - GitHub - oplik0/nodebb-plugin-total-vote-count: Calculate vote totals based on all posts in topics and not just the inital post
GitHub (github.com)
-
@crazycells now this is definitely a plugin I'm going to use. Nobody up votes the original topic, but always the individual posts.
-
@phenomlab yeap, we have both cases in the forum, but this calculation makes more sense to us than the first post only.
-
@crazycells said in Total vote count on topic list:
but this calculation makes more sense to us than the first post only.
And for me.