• Correct me if I'm wrong, but I don't think nodebb supports read/unread logic in groups out of the box. Is it possible to add this via plugin ?

  • NodeBB Admin

    What do you mean by read/unread in groups?


  • @baris similar to topics list in category view, when there is a new topic that you haven't read, the color of the font shows blue (depending on your theme). All read topics are in black. I believe there is a logic somewhere that adds an 'unread' class to the element that changes the color of the font, but I don't know if this is possible to the posts/topics found in the group page.

  • NodeBB Admin

    It is not possible out of the box since that logic only works on lists of topics and not posts(group page is displaying posts). A plugin can do it by looking at the topics of those posts and determine if they are read/unread and alter the template.


  • @baris is it correct that I should listening for filter:post.getPostSummaryByPids to have access to the posts > topic located in groups?

    Screen Shot 2020-07-09 at 15.49.35 PM.png

  • NodeBB Admin

    That hook is triggered on other places as well. If you only want to do this modification on the groups page. I suggest you use the hook filter:groups/details.build. The same data is available in templateData

    myPlugin.filterGroupsDetailsBuild = async (hookData) => {
       console.log(hookData.templateData);
       return hookData;
    };
    
  • NodeBB Admin

    And yes you can add unread class into the topic object, you will have to modify the template to use that variable and apply some styling as well.


  • @baris Awesome! Giving this a shot now!


  • @baris can't seem to access 'topic' under posts. Can you tell me what's wrong with me code?

    myPlugin.filterGroupsDetailsBuild = async (hookData) => {
      const pids = hookData.templateData.posts.map(t => t.pid);
      const getTopic = await topics.getUnreadData(pids);
      hookData.templateData.posts.forEach((t, i) => {
          t.foobar = getTopic[i];
      });
      return hookData;
    };
    
  • NodeBB Admin

    topics.getUnreadData doesn't take an array of pids. You should use Topics.hasReadTopics(tids, uid);

Suggested Topics

| |