How to retrieve archived messages in the reverse order with XMPPFramework?

417 Views Asked by At

I'm implementing retrieving XMPP chat history with XEP-0313 Message Archive Management using XMPPFramework for iOS. I receive messages page by page using XMPPFramework's class XMPPMessageArchiveManagement. I'm able to receive the pages in the reverse order providing the message before which the next page should be.

let resultSet = XMPPResultSet(max: 50, before: theIdOfTheOldestReceivedMessage ?? "")
self.xmppMAM?.retrieveMessageArchive(at: to,
                                     withFields: [field],
                                     with: resultSet)

But I also would like to receive the messages on each page in the reverse order from the last one to the first one. According to the documentation I should provide the element in the query:

A client wishing for a reversed page should include the <flip-page/> element in its query, like so:

<iq type='set' id='q29309'>
    <query xmlns='urn:xmpp:mam:2'>
        <x xmlns='jabber:x:data' type='submit'>
            <field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:2</value></field>
            <field var='start'>\<value>2010-08-07T00:00:00Z\</value>\</field>
        </x>
        <set xmlns='http://jabber.org/protocol/rsm'>
            <max>10</max>
            <after>09af3-cc343-b409f\</after>
        </set>
        <flip-page/>
    </query>
</iq>

The source: https://xmpp.org/extensions/xep-0313.html#query-paging-flip.

The problem is that I don't populate the query myself: XMPPFramework is responsible for that. The framework generates the final XML and I'm only able to provide fields and a result set. The provided fields will be inside the x element, the provided result set will be a separate element of the queue. But how to provide the <flip-page/> element to the queue with XMPPMessageArchiveManagement by XMPPFramework?

0

There are 0 best solutions below