【问题标题】:get the fullname of a each user in the roster openfire xmpp strophe获取名册中每个用户的全名 openfire xmpp strophe
【发布时间】:2013-10-21 20:13:54
【问题描述】:

这将查询我名册中的所有联系人列表,但它只允许我查询 JID 而不是全名。如何查询名册并获取每个名称?

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

谢谢。

【问题讨论】:

    标签: xmpp openfire strophe


    【解决方案1】:
     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*/
            );
    

    你也可以搭配

    <iq from='userroster@jabber.org'
        id='v1'
        type='get'>
      <vCard xmlns='vcard-temp'/>
    </iq>
    

    获取每个用户的电子名片,然后获取全名。

    试试看。

    【讨论】:

    • 是的,但我如何用 Strophe 的方式翻译它?
    • 通过查询 jid 是不可能的,另一种解决方案,如果你想获得完整是当你添加/更新你的名册时,你可以将名称设置为全名,这样:var contact = {jid: 'me@jabber.org', name: '我的全名'}; var iq = $iq({type: 'set'}).c('query', {xmlns: 'jabber:iq:roster'}).c('item', {jid: contact.jid, name: contact .name});
    • 但是当我要求一个名册名称时,并不是每个项目都来。我在花名册上找到了这个。 朋友
    猜你喜欢
    • 2013-01-04
    • 2013-12-29
    • 2015-05-24
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 2014-04-12
    • 2011-07-04
    • 2013-12-15
    相关资源
    最近更新 更多