Trevor Newhook
Trevor Newhook

Reputation: 909

How to loop through groups with now.js

is there a way to loop through a user's groups with now.js?

When a user disconnects, I want to run some functions on the groups that they were a part of.

something like answer 1 here (1), but for some reason, that code doesn't work.

Code:

nowjs.on('disconnect', function() { 
    var that = this;
    this.getGroups(function(groups){
         for (i=0;i<groups.length;i++){
             nowjs.getGroup(groups[i]).removeUser(that.user.clientId);
             console.log('user removed');
         }
    })
})

Upvotes: 0

Views: 103

Answers (1)

Trevor Newhook
Trevor Newhook

Reputation: 909

I forgot that I had already created an array called serverRoomsList. That held, oddly enough, a list of all the chat rooms I had already created. I just looped through that to get all of the group names.

However, I would still like to know if Now itself keeps track of groups in an array, or if I have to do it.

Upvotes: 0

Related Questions