简体   繁体   English

使用smack从消息存档openfire获取最新对话

[英]fetching newest conversation from message archive openfire using smack

Hello guys, I'm using these lines of code to fetch list of conversation using smack 大家好,我正在使用以下几行代码通过smack获取会话列表

@Override
protected Void doInBackground(String... strings) {

    final ArrayList<UsersData> users 
        = UsersManager.getInstance().getUsers();

    int count = 0;
    while(count < users.size()) {

        try {
            Thread.sleep(500);
            final String jid 
                = users.get(count).getUserJID();

            IQ iq = new IQ() {

                @Override
                public String getChildElementXML() {
                    String list = "<list xmlns='urn:xmpp:archive'"+
                            "with='"+jid+"'>"+
                            "<set xmlns='http://jabber.org/protocol/rsm'>"+
                            "<max>30</max></set></list>";
                    return list;
                }
            };

            iq.setType(IQ.Type.GET);
            iq.setPacketID(jid+System.currentTimeMillis());

            service.getXmppConnection().sendPacket(iq);
            Log.v("XmppAsyncHistory", "IQ List sent!");

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        count++;
    }

    return null;
}

I've added my iq provider. 我添加了我的智商。

        provider.addIQProvider("list", "urn:xmpp:archive", new ListIQProvider());

And I get this stanza for reply. 我得到此节以供回复。

D/SMACK(11130): 10:34:30 PM RCV  (1096010080): 
<iq type="result" 
id="24@suitmedia1375112070174" 
to="17@suitmedia/Smack"><list xmlns="urn:xmpp:archive">
chat with="24@suitmedia" 
 start="2013-07-25T09:57:04.121Z"/>
<chat with="24@suitmedia"  
 start="2013-07-25T11:08:28.997Z"/>
<chat with="24@suitmedia" 
 start="2013-07-29T09:29:18.295Z"/>
<chat with="24@suitmedia" 
 start="2013-07-29T07:47:29.841Z"/>
<set  xmlns="http://jabber.org/protocol/rsm">
<first index="0">184</first><last>216</last>
<count>4</count></set></list></iq>

As you can see, it returns not the newest conversation, instead the oldest one from 25/07 to 29/07 respectively 如您所见,它不会返回最新的对话,而是分别返回25/07到29/07的最旧的对话

What I want to ask is what do these tags means? 我想问的是这些标签是什么意思? 184216 And how can I get conversation list order by recent time? 184216并且如何获得最近时间的会话列表顺序?

Thank you! 谢谢!

You should add an attribute "end" to your "list" element with current time. 您应该将带有当前时间的属性“ end”添加到“ list”元素中。 The XML will look like: XML将如下所示:

<iq type='get' xmlns='jabber:client'><list xmlns='urn:xmpp:archive' end='2014-05-28T08:48:56+08:00' with='somebody@somesite'><set xmlns='http://jabber.org/protocol/rsm'><max>10</max><before/></set></list></iq>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM