Spent hours trying to solve this problem and I'm stumped!
Trying to grab the Chat History between 2 users on my OpenFire server and I read that I plugin was needed to do this.
So, I installed the 'Open Archive' plugin on my OpenFire server and send the following XML (as per the XMPP-0136 protocol documentation):
<iq type="get" id="page1">
<retrieve xmlns="urn:xmpp:archive" with="username@server.com" start="1469-07-21T02:56:15Z">
<set xmlns="http://jabber.org/protocol/rsm">
<max>100</max>
</set>
</retrieve>
</iq>
In code, this is achieved via the following:
NSXMLElement *iQ = [NSXMLElement elementWithName:@"iq"];
[iQ addAttributeWithName:@"type" stringValue:@"get"];
[iQ addAttributeWithName:@"id" stringValue:@"page1"];
NSXMLElement *retrieve = [NSXMLElement elementWithName:@"retrieve"];
[retrieve addAttributeWithName:@"xmlns" stringValue:@"urn:xmpp:archive"];
[retrieve addAttributeWithName:@"with" stringValue:@"username@server.com"];
[retrieve addAttributeWithName:@"start" stringValue:@"1469-07-21T02:56:15Z"];
NSXMLElement *set = [NSXMLElement elementWithName:@"set"];
[set addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/rsm"];
NSXMLElement *max = [NSXMLElement elementWithName:@"max"];
max.stringValue = @"100";
[set addChild:max];
[retrieve addChild:set];
[iQ addChild:retrieve];
[[[self appDelegate] xmppStream] sendElement:iQ];
Which returns the following error:
<iq xmlns="jabber:client" type="error" id="page1" to="username@server.com">
<error code="404" type="cancel">
<item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
My Xcode project can successfully send/receive messages to the user I'm trying to receive chat history from so I really don't know what I'm doing wrong. Also the Plugin enables me to search through Chat Messages (via OpenFire admin) with successful results so it seems to be working and storing the messages.
Any help would be appreciated. Thanks!
When you mention start tag in the request then it matches with the chat having the exact time stamp that's why it returns error code '404' or '500'. I ommited start tag from my request and wrote following code which returns whole chat history with the user.
Here this will return whole chat history in XML response between user Rahul and the user currently logged in.
For more detailed info please refer this blog http://question.ikende.com/question/363439343236313430
If you are looking for a chat history, I think you have to save the messages to core data and retrieve them from there. For saving data using the XMPPFramework inbuilt functionality, you have to use this code:
Now you have to retrieve that messages from core data by this:
XMPPFramework implements XEP-0136. Have you tried using XMPPMessageArchiving to set preferences or synchronize the server's archive to the client?
Please have a detailed Stanza detail at : https://stackoverflow.com/a/29097289/2225439
It is Platform independent just you need to understand the structure of Stanza and can be created as per the libraries that you are using.
This is the Series of Stanza that you will need to send to get Archived Messages. For more detail you can checkout XEP 0136 (http://xmpp.org/extensions/xep-0136.html#manual)
REQ
RES
REQ
RES
To Fetch List of all Conversations