Retrieve history chat Openfire XMPP framework

2019-01-12 07:52发布

问题:

I've developed a chat app using XMPPframwork of Robbie Hanson and Openfire server. I can chat one to one and chat group successfully. But when I get history of chat, I can't get whole history. I use XEP-0136 to archieve history:

Send IQ:

 <iq type="get" id="hichic@macintosh">
    <retrieve
        xmlns="urn:xmpp:archive" with="group12@conference.macintosh">
        <set
            xmlns="http://jabber.org/protocol/rsm">
            <max>100</max>
        </set>
    </retrieve>
</iq>

Receive:

<iq type="result" id="hichic@macintosh" to="admin@macintosh/Macintosh">
    <chat
        xmlns="urn:xmpp:archive" with="group12@conference.macintosh" start="2016-08-23T08:42:55.777Z">
        <to secs="0">
            <body>asdf</body>
        </to>
        <to secs="5">
            <body>aafs</body>
        </to>
        <from secs="2" jid="haha@macintosh">
            <body>sax</body>
        </from>
        <set
            xmlns="http://jabber.org/protocol/rsm">
            <first index="0">0</first>
            <last>2</last>
            <count>3</count>
        </set>
    </chat>
</iq>

But when I open the database, ofMessageArchive table, I can see much more messages with group12 (~20 messages) while in the result, I only got 3. May I miss something?

回答1:

Follow this format, it works for me perfectly,

<iq id='a5sV8-21' type='set'>
    <query xmlns='urn:xmpp:mam:0' queryid="12345678">
        <x xmlns="jabber:x:data" type="submit">
            <field var="FORM_TYPE" type="hidden"><value>urn:xmpp:mam:0</value></field>
            <field var="with"><value>id@domain</value></field>
        </x>
        <set xmlns="http://jabber.org/protocol/rsm">
            <max>message_count</max>
        </set>
    </query>
</iq>

** If xmpp:mam:0 doesn't work use xmpp:mam:1