leeshin
leeshin

Reputation: 1043

get the fullname of a each user in the roster openfire xmpp strophe

This will query all the list of contacts in my roster,but it only allows me to query the JID and not the fullname. How do I query the roster and get each name?

$(document).bind('connected', function(){
   var iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});
});

Thanks.

Upvotes: 1

Views: 1873

Answers (1)

rubStackOverflow
rubStackOverflow

Reputation: 6163

 var iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});
conn.sendIQ(iq,
            function success(iq){
                $(iq).find('item').each(function () { //all contacts 
                    var jid = $(this).attr('jid');
                    var name = $(this).attr('name') || jid;
                    var subscr = $(this).attr('subscription'); //type subscription
                    console.log('contacts: jid:' + jid + '  Name:' + name);
                });
            },
            function failure(iq){
                console.log(iq);
            },30000/*timeout sendIQ*/
        );

Also you can mix with

<iq from='[email protected]'
    id='v1'
    type='get'>
  <vCard xmlns='vcard-temp'/>
</iq>

To get vcard's of each user and then get full name.

Try it.

Upvotes: 1

Related Questions