iOS: XMPP: Message Archiving for Group Chat Message

别说谁变了你拦得住时间么 提交于 2019-12-01 09:14:01

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='mrug_sender@staging.openfire.com'>
       <list xmlns='urn:xmpp:archive'
               with='mrug_target_155@staging.openfire.com'>
        <set xmlns='http://jabber.org/protocol/rsm'>
            <max>6900</max>
        </set>
      </list>
   </iq>

RES

<iq type="result" id="mrug_sender@staging.openfire.com" to="mrug_sender@staging.openfire.com/Psi">
<list xmlns="urn:xmpp:archive">
<chat with="mrug_target_155@staging.openfire.com" start="2014-06-07T06:52:26.041Z"/>
<chat with="mrug_target_155@staging.openfire.com" 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='mrug_sender@staging.openfire.com'>
    <retrieve xmlns='urn:xmpp:archive'  with='mrug_target_155@staging.openfire.com'  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="mrug_sender@staging.openfire.com" to="mrug_sender@staging.openfire.com/Psi">
    <chat xmlns="urn:xmpp:archive" with="mrug_target_155@staging.openfire.com" start="2014-06-07T06:52:26.041Z">
    <from secs="0" jid="mrug_target_155@staging.openfire.com">
    <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='mrug_sender@staging.openfire.com'>
       <list xmlns='urn:xmpp:archive'>
        <set xmlns='http://jabber.org/protocol/rsm'>
            <max>6900</max>
        </set>
      </list>
</iq>

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!