3

I have a chat app in which I want to retrieve chat history between two users, I have a stanza for retrieving chat messages and that is...

    <iq type='get' id='pk1'>
<list xmlns='urn:xmpp:archive'
with='shrey27@sys1-pc'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>30</max>
</set>
</list>
</iq>

now, my problem is how can I fire this stanza to the server so that I can get the response.I have installed the message archiving plugin and messages are getting stored perfectly.any suggestions would be beneficial... thanks in advance!!!

Shrey
  • 248
  • 3
  • 14

1 Answers1

4
NSXMLElement *iQ = [NSXMLElement elementWithName:@"iq"];
[iQ addAttributeWithName:@"type" stringValue:@"get"];
[iQ addAttributeWithName:@"id" stringValue:@"987654321"];

NSXMLElement *list = [NSXMLElement elementWithName:@"list"];
[list addAttributeWithName:@"xmlns" stringValue:@"urn:xmpp:archive"];
[list addAttributeWithName:@"with" stringValue:@"bhushan@mydomain.com"];



NSXMLElement *set = [NSXMLElement elementWithName:@"set"];
[set addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/rsm"];

NSXMLElement *max = [NSXMLElement elementWithName:@"max"];
[max addAttributeWithName:@"xmlns" stringValue:@"http://jabber.org/protocol/rsm"];
max.stringValue = @"30";

[set addChild:max];

[list addChild:set];
[iQ addChild:list];
[[[self appDelegate] xmppStream] sendElement:iQ];

You can call like this. Hope this helps :)

Karun
  • 880
  • 1
  • 8
  • 19
  • 1
    Hi Karun, Thanks for this helpful piece of code. When I am executing the code in my app the server gives me response as **service-unavailable** with error code 503. Can you please suggest where I may be going wrong. The response comes in delegate method `- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq`. Thanks. – Yogi Feb 20 '15 at 06:16
  • @Yogi I am facing same issue. Did you find your solution? – Hassan Aftab Mar 09 '16 at 14:03
  • I am getting Error 501 if that thing i implement in Swift 3. feature not implemented – Mad Burea Jan 23 '17 at 11:38
  • You also need Openfire Pluging installed in Openfire Server but you will not get exact what you want http://stackoverflow.com/questions/42084375/while-fetching-chat-history-i-am-not-getting-both-user-history-from-openfire – Mad Burea Feb 07 '17 at 08:09