How to retrieve chat history from open fire in android
Asked Answered
A

1

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!!!

Alp answered 9/2, 2014 at 9:43 Comment(0)
S
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:@"[email protected]"];



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 :)

Saccharose answered 10/3, 2014 at 12:43 Comment(4)
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.Annitaanniversary
@Annitaanniversary I am facing same issue. Did you find your solution?Roseannaroseanne
I am getting Error 501 if that thing i implement in Swift 3. feature not implementedAzov
You also need Openfire Pluging installed in Openfire Server but you will not get exact what you want #42084875Azov

© 2022 - 2024 — McMap. All rights reserved.