3

How can I retrieve the list of members of a chat room in using XMPP framework?

I tried using:

 - (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items 

But it returns an empty array

Adam Richardson
  • 2,518
  • 1
  • 27
  • 31
Geet
  • 2,427
  • 2
  • 21
  • 39
  • Did you check your chat room settings for Anonymous joining? If it is enabled you might not get the list of users in the room. – ashokbabuy Aug 13 '13 at 06:10
  • Are you using this type of chatrooms, XMPP + Jabber? http://code.tutsplus.com/tutorials/building-a-jabber-client-for-ios-xmpp-integration--mobile-7190 – Mrunal Dec 19 '14 at 16:18

2 Answers2

7

This question is old but I recently encountered this exact issue (xmppRoom:didFetchMembersList: is passed an empty array). In my case the problem was that when users got invited to the room they would have a role of "participant" and an affiliation of "none". The fetchMembersList method in XMPPRoom looks for items with an affiliation of "member".

You can change the affiliation like so:

[xmppRoom editRoomPrivileges:@[[XMPPRoom itemWithAffiliation:@"member" jid:userJID]]];

For details on roles and affiliations, see XEP-0045.

onelittlefish
  • 227
  • 3
  • 6
  • Hi, @onelittlefish I tried you code and it was of big help! But, I tried it in a public room with a user that just joined and it didn't worked, it only worked if the owner of the group tried to give permissions...any Idea how I can bypass this? Here is my [post](http://stackoverflow.com/questions/29701372/join-an-existing-xmpp-muc-room-with-owner-privileges-using-ios-openfire-and-robb), hope you could help :) – Laur Stefan Apr 17 '15 at 14:41
2

use this method when you invite users.

-[xmppRoom editRoomPrivileges:@[[XMPPRoom itemWithAffiliation:@"member" jid:userJID]]];

After you create xmpproom object and call following delegate method

-(void)xmppRoomDidJoin:(XMPPRoom *)sender{
    [sender fetchMembersList];
}


- (void)xmppRoom:(XMPPRoom *)sender didFetchMembersList:(NSArray *)items{
    NSLog(@"print user list=====%@",items);
    for (NSXMLElement *xmlItem in items) {
        NSString *jid = [[xmlItem attributeForName:@"jid"]stringValue];
          NSLog(@"print user jid=====%@",jid);
    }
}
TMD
  • 380
  • 2
  • 8