【问题标题】:xmpp - how to get room chat historyxmpp - 如何获取房间聊天记录
【发布时间】:2015-08-31 23:35:32
【问题描述】:

我正在使用 iOS xmpp 框架。 我想在需要时获取房间聊天记录。这样有一个按钮,当点击按钮时,每次会收到20条历史消息。

如果我有 100 条历史消息,我点击按钮 5 次,那么我将获得所有历史消息。

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

此方法只能使用一次。

【问题讨论】:

    标签: history xmppframework chatroom muc


    【解决方案1】:

    我用这个方法,但是什么都能收到。

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

    发送和接收的消息:

    SEND: 
    <presence to="ios@conference.192.168.1.67/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="ios@conference.192.168.1.67/myNickname" to="test1@192.168.1.67/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="test1@192.168.1.67/14392264591434445057383183" affiliation="owner" role="moderator"/><status code="110”/>
    </x></presence>
    

    【讨论】:

      【解决方案2】:

      发送历史记录 nil 和 openfire 中的 alos 更新 打开你的 openfire 网址,然后点击群聊 > 群聊设置 > 你的群组 > 历史设置

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

      【讨论】:

      • 这会在进入房间时获取所有历史记录。我想按需获取历史消息。加入房间后,我想随时获取历史消息。
      • 如果你想要历史,那么你必须加入一个组,你可以更改历史消息的值。如果想要更多历史更改 10 到 50 或任何您想要的,请使用此代码 NSXMLElement *history = [NSXMLElement elementWithName:@"history"]; [history addAttributeWithName:@"maxstanzas" stringValue:@"10"]; [xmppRoom1 joinRoomUsingNickname:@"myNickname" history:history password:nil];
      • 谢谢 suthar。我知道我可以在进入房间时收到房间历史信息。但这还不够。如果有很多历史消息(例如,10000 条),我无法一次获取所有历史消息。我需要将获取历史消息请求分成几个小请求。这样一进房间就可以收到100条消息,按更多按钮会再收到100条消息。
      • 获取所有历史消息,然后保存到数据库,然后如果您需要最后 50 条消息,请从本地数据库获取这些消息
      • 嗨,@KishoreSuthar 你能告诉我在获取一对一聊天时需要发送哪个 iq 请求吗?我尝试了很多方法,但得到一个错误代码,如 405、500。
      猜你喜欢
      • 1970-01-01
      • 2016-06-26
      • 1970-01-01
      • 2016-11-09
      • 2014-01-05
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多