How to get all the groups that the user subscribed to?


  • Gamers

    How to get all the groups that the user subscribed to? I see this functionality in some forums that use lavender as their base theme. I want to get all the groups details that the user subscribed to.

    Someone said that i need to change the core of the nodebb to do this. But i don't think i need to.


  • Community Rep

    On the server, you can do

    var groups = require.main.require('./src/groups');
    groups.getUserGroups([1] /*array of uids*/, function(err, userGroups){
    	if (err) return;
    	// Returns an array of an array of group data.
    	console.log(userGroups[0]); // Prints an array of groups for uid 1
    });
    

    on the client, you can get a list of visible groups by doing:

    $.getJSON('/api/user/USERSLUG/groups', function (data) {
        // Returns an object with a 'groups' property, an array of visible group data.
        console.log(data.groups);
    });
    

 

| |

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.