iOS: XMPP: Message Archiving for Group Chat Message
Asked Answered
S

2

4

All one-one chat is send with Message Type as Chat. Thus the Message Archiving technique (shown below) worked fine for me to save/retrieve chat history.

// Setup message archiving
xmppMessageArchivingStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
xmppMessageArchiving = [[XMPPMessageArchiving alloc] initWithMessageArchivingStorage:xmppMessageArchivingStorage];
[xmppMessageArchiving setClientSideMessageArchivingOnly:YES];

// Activate xmpp modules
[xmppMessageArchiving   activate:xmppStream];
// Add delegate
[xmppMessageArchiving  addDelegate:self delegateQueue:dispatch_get_main_queue()];

However for Group Chat, the message type sent is "groupchat" This will not be archived by the XMPPMessageArchivingCoreDataStorage


Can someone please guide me as to how I can achieve the Message Archiving for Group Chat Message.

Sacramental answered 8/8, 2014 at 8:45 Comment(3)
Y you need archive room messages.If u joined a new room , u can get all messages already there in that roomIncise
But I would want all messages saved even after I have joined it. So that I can show all messages right from the archive.Sacramental
if you any sample code or project to get chat history from ejbberd server in iOS swift.Sandoval
U
2

This is the Series of Stanza that you will need to send to get Archived Messages. For more detail you can checkout http://xmpp.org/extensions/xep-0136.html

REQ

<iq type='get' id='[email protected]'>
       <list xmlns='urn:xmpp:archive'
               with='[email protected]'>
        <set xmlns='http://jabber.org/protocol/rsm'>
            <max>6900</max>
        </set>
      </list>
   </iq>

RES

<iq type="result" id="[email protected]" to="[email protected]/Psi">
<list xmlns="urn:xmpp:archive">
<chat with="[email protected]" start="2014-06-07T06:52:26.041Z"/>
<chat with="[email protected]" start="2014-06-07T07:06:53.372Z"/>
<set xmlns="http://jabber.org/protocol/rsm">
<first index="0">866</first>
<last>867</last>
<count>2</count>
</set>
</list>
</iq>

REQ

<iq type='get' id='[email protected]'>
    <retrieve xmlns='urn:xmpp:archive'  with='[email protected]'  start='2014-06-07T06:52:26.041Z'>
     <set xmlns='http://jabber.org/protocol/rsm'>
       <max>8000</max>
     </set>
    </retrieve>
 </iq>

RES

 <iq type="result" id="[email protected]" to="[email protected]/Psi">
    <chat xmlns="urn:xmpp:archive" with="[email protected]" start="2014-06-07T06:52:26.041Z">
    <from secs="0" jid="[email protected]">
    <body>Wow !! This is Archived Message</body>
    </from>
    <set xmlns="http://jabber.org/protocol/rsm">
    <first index="0">0</first>
    <last>0</last>
    <count>1</count>
    </set>
    </chat>
    </iq>

To Fetch List of all Conversations

<iq type='get' id='[email protected]'>
       <list xmlns='urn:xmpp:archive'>
        <set xmlns='http://jabber.org/protocol/rsm'>
            <max>6900</max>
        </set>
      </list>
</iq>
Underexpose answered 17/3, 2015 at 10:55 Comment(3)
Hello @Mrug, I used github.com/robbiehanson/XMPPFramework. I don't know how to store these retrieved messages please help me with this.Imphal
Just follow the above series of Stanza you will get the response in XML, which you will need to parse and store either in SQLite or Coredata.Underexpose
I used XMPPFramework and this framework automatically stores the messages and I want to store these archived messages with coredata database which is created by XMPPFramework so the problem is I am not able to store these messages @UnderexposeImphal
S
1

You can easily get archive messages from xmpp core database. Use Below code.

XMPPMessageArchivingCoreDataStorage *_xmppMsgStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
NSManagedObjectContext *moc = [_xmppMsgStorage mainThreadManagedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"XMPPMessageArchiving_Message_CoreDataObject"
                                                     inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
[request setEntity:entityDescription];
//[request setFetchLimit:20];

NSError *error;
NSString *predicateFrmt = @"bareJidStr == %@";

NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFrmt, [NSString stringWithFormat:@"%@%@",GroupName,GROUP_CHAT_DOMAIN]];
request.predicate = predicate;
NSArray *messages = [moc executeFetchRequest:request error:&error];
Sherleysherline answered 4/6, 2015 at 5:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.