Reputation: 2437
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
Upvotes: 3
Views: 2111
Reputation: 380
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);
}
}
Upvotes: 2
Reputation: 339
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.
Upvotes: 7