Display Group Badge On Topic List?



  • Hello,

    I'm trying to create a plugin that shows the group badge next to the username on the topic list. It's very similar to this, but on the topic list.

    Thank you in advance!



  • EDIT:

    I'm trying to create a plugin that shows the group badge next to or below the topic name. The idea is to notify the readers that a 'dev' or 'admin' has posted/responded to the topic.

    Are there any plugins available that can do this? Is it possible to create?

    Thank you in advance!


  • Admin Staff

    This shouldn't be hard to do, listen for filter:topics.get and then load the users groups into the user object. Once that is done you can display them on partials/topics_list.tpl

    myPlugin.filterTopicsGet = async function (hookData) {
      const uids = hookData.topics.map(t => t.uid);
      const userGroups = await Groups.getUserGroups(uids);
      hookData.topics.forEach((t, i) => {
          t.user.groups = userGroups[i];
      });
      return hookData;
    };
    

    This would create a groups variable on every user object which you can access in the template.



  • @baris Thank you for this. I can now see the groups variable for users listed on the topics page. I do have a follow up question. Is there a way for us to access all posts (including users) in a topic from the topics page? Our goal is to dynamically place a badge under the topic title to indicate that a dev had posted/replied in the topic.


  • Admin Staff

    @Teemberland For this you can use the sorted set tid:<tid>:posters it contains all uids who have posted in the topic (including the OP) and the score is the number of posts they have in that topic. So you need to grab the uids from this sorted set and check if any of the uids are in a dev group.


Log in to reply
 

Suggested Topics

  • 2
  • 1
  • 6
  • 10
  • 1
| |