Exclude ignored Topics from Recent Topics widget (nodebb-widget-essentials)

Plugin Development
  • Hi,
    is there a possibility to exclude ignored topics (or whole categories) from the recent topics widget?
    If I ignore a category, the topics still appear in the recent topics widget.

    Best regards

  • Hi @baris,

    I see that you closed the issue for nodebb-plugin-recent-cards. I'm now trying to adopt your changes for nodebb-widget-essentials recent topics widget. If I compare the code of library.js it's bit different though.

    I assume that I can use topics.getSortedTopics instead of topics.getTopicsFromSet like you do for nodebb-plugin-recent-cards but I'm not sure how to handle the 'key' value that has been initialized before. My idea is something like this:

    		const data = await topics.getSortedTopics({
    			uid: widget.uid,
    			start: 0,
    			stop: numTopics,
    			sort: widget.data.sort

    In recent-cards this call was used before:

    topicsData = await getTopicsFromSet(map[widget.data.sort], 0, 19);

    In widget-essentials this call is used:

    const data = await topics.getTopicsFromSet(key, widget.uid, 0, Math.max(0, numTopics));

    Help will be appreciated.

    best regards

  • getSortedTopics doesn't use a key, it uses determines what set to use based on the sort parameter. It also filters out ignored topics and categories.
    The recent topics widget in widget-essentials also allows using different category ids(cids) so make sure to pass those to getSortedTopics like this.

    const data = await topics.getSortedTopics({
      cids: cids,
      uid: widget.uid,
      start: 0,
      stop: numTopics,
      sort: 'recent',
      teaserPost: 'last',
  • Thank you @baris

    This is working if you ignore a certain topic. It doesn't seem to work for whole ignored categories, so the topics stilI appear in the widget then. I don't use recent-cards but is it working there?

  • Do you have category ids defined in the widget settings? You can see how getSortedTopics ignores categories here https://github.com/NodeBB/NodeBB/blob/master/src/topics/sorted.js#L180-L189.

    If you pass in a category ids to getSortedTopics it will return topics from those categories even if the user has ignored some of those cids. This is by design, this allows the user to load /recent?cid=<some_ignored_cid> to see topics if they want. If you don't want that behaviour you can filter the cids before passing them to the function.

    const isIgnored = await categories.isIgnored(topicCids, uid); will return an array of booleans for each category id you pass in.

  • @baris said in Exclude ignored Topics from Recent Topics widget (nodebb-widget-essentials):

    Do you have category ids defined in the widget settings?

    Yes I do, that makes it clear.

    I'm thinking about the best way to implement your mentioned filtering.

    for(int i = 0; i < cids.length; i++) {
      const isIgnored = await categories.isIgnored(cids[i], widget.uid);
      for(int j = i; j < isIgnored.length; j++) {
         if(isIgnored[j]) {
           // remove from cids array? 

    I know there is an Array.filter() function so I'm pretty sure there is a better/easier way?

Suggested Topics