[Solved] Help with hook on getting recent topic topics


  • Hello everyone! I have the following issue while developing a new theme for NodeBB.

    We are adding upvote/downvote capability to topics from the topics list like in the following image b81746cb-2841-4fd4-b1f2-4ae8a9d0cf84-imagen.png

    In order to add voting/downvoting to theme topics from the categories list like the following we added this method

    library.getCategoryHook = async function(data) {
    	const topics = data.topics;
    	const uid = data.uid;
    	const promises = topics.map(async (topic) => {
    		const hasVoted = await posts.hasVoted(topic.mainPid, uid);
    		return {
    			...topic,
    			upvoted: hasVoted.upvoted,
    			downvoted: hasVoted.downvoted,
    			enableVoting: uid !== 0 && data.uid !== topic.uid
    		}
    	});
    	data.topics = await Promise.all(promises);
    	return data;
    }
    

    This is called using the hook filter:category.topics.get and it works for the topics list but if I try to go to the recent topics view, this hook is not called. Other possibility would be to load the information on page enter but I'm not sure how to do that, any suggestions?

    Thanks for any help

  • Global Moderator

    @asdrubalivan have you tried using filter:topics.get instead? I'd think it would cover both cases.


  • No. I just tried and it works @PitaJ. I just changed the hook and it worked. Thank you so much! This is now solved

Suggested Topics

| |