【问题标题】:iOS: XMPP: Message Archiving for Group Chat MessageiOS:XMPP:群聊消息的消息归档
【发布时间】:2014-10-01 16:32:19
【问题描述】:

所有一对一聊天都以消息类型作为聊天发送。 因此,消息存档技术(如下所示)对我保存/检索聊天记录非常有效。

// 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()];

但是对于群聊,发送的消息类型是“群聊” 这不会被 XMPPMessageArchivingCoreDataStorage 归档


有人可以指导我如何实现群聊消息的消息存档。

【问题讨论】:

  • 你需要存档房间消息。如果你加入了一个新房间,你可以得到那个房间里已经存在的所有消息
  • 但我希望即使在我加入后也能保存所有消息。这样我就可以直接显示存档中的所有消息。
  • 如果你有任何示例代码或项目可以在 iOS swift 中从 ejbberd 服务器获取聊天记录。

标签: ios xmpp message xmppframework archiving


【解决方案1】:

这是您需要发送以获取存档消息的一系列节。更多详情可以查看http://xmpp.org/extensions/xep-0136.html

请求

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

回复

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

请求

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

回复

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

获取所有对话列表

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

【讨论】:

  • 你好@Mrug,我使用了github.com/robbiehanson/XMPPFramework。我不知道如何存储这些检索到的消息,请帮助我。
  • 只要按照上面的 Stanza 系列,您将获得 XML 格式的响应,您需要解析并存储在 SQLite 或 Coredata 中。
  • 我使用了 XMPPFramework,该框架自动存储消息,我想将这些归档消息存储在由 XMPPFramework 创建的 coredata 数据库中,所以问题是我无法存储这些消息@Mrug跨度>
【解决方案2】:

您可以轻松地从 xmpp 核心数据库获取存档消息。使用下面的代码。

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];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-13
    • 2015-12-22
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多