xmpp - how to get room chat history

2.6k views Asked by At

I am using the iOS xmppframework. I want to get room chat history when needed. Such that there is a button, when click the button, 20 history messages will be received each time.

If I have 100 history messages, I click the button 5 times, then I will get all the history message.

[xmppRoom1 joinRoomUsingNickname:@"myNickname" history:history password:nil];

this method can only used once.

2

There are 2 answers

5
Kishore Suthar On BEST ANSWER

Send history nil and alos update in openfire open your openfire url then click on Group chat > Group Chat setting > your group > history setting

enter image description here

XMPPRoomMemoryStorage *roomStorage = [[XMPPRoomMemoryStorage alloc] init];
        XMPPJID *roomJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.51.101.97.21",groupName]];
        XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomStorage
                                                               jid:roomJID
                                                     dispatchQueue:dispatch_get_main_queue()];

        [xmppRoom activate:xmppStream];
        [xmppRoom addDelegate:self
                delegateQueue:dispatch_get_main_queue()];
        [xmppRoom joinRoomUsingNickname:xmppStream.myJID.user
                                history:nil
                               password:nil];
0
xhsoldier On

I use this method, but can receive anything.

NSXMLElement *history = [[NSXMLElement alloc] initWithName:@"history"];
[history addAttributeWithName:@"maxstanzas" stringValue:@"5"];

NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:XMPPMUCNamespace];
if (history)
{
    [x addChild:history];
}
XMPPPresence *presence = [XMPPPresence presenceWithType:nil to:xmppRoom1.myRoomJID];
[presence addChild:x];
[xmppStream sendElement:presence];

The message sent and received:

SEND: 
<presence to="[email protected]/myNickname”>
<x xmlns="http://jabber.org/protocol/muc”>
    <history maxstanzas="5”/>
</x>

<x xmlns="vcard-temp:x:update"><photo/></x>
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://github.com/robbiehanson/XMPPFramework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4=“/>

</presence>


RECV: 
<presence xmlns="jabber:client" from="[email protected]/myNickname" to="[email protected]/14392264591434445057383183”>
<x xmlns="vcard-temp:x:update"><photo/></x>
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://github.com/robbiehanson/XMPPFramework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4=“/>
<x xmlns="http://jabber.org/protocol/muc#user”>
<item jid="[email protected]/14392264591434445057383183" affiliation="owner" role="moderator"/><status code="110”/>
</x></presence>