xmpp - 如何获取房间聊天记录
xmpp - how to get room chat history
我正在使用 iOS xmpp 框架。
我想在需要时获取房间聊天记录。比如有一个按钮,点击按钮,每次会收到20条历史消息。
如果我有 100 条历史消息,我点击按钮 5 次,然后我将获得所有历史消息。
[xmppRoom1 joinRoomUsingNickname:@"myNickname" history:history password:nil];
此方法只能使用一次
我用这个方法,但是什么都能收到
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>
发送历史记录为零
并在 openfire 中更新
打开你的 openfire url 然后点击群聊 > 群聊设置 > 你的群 > 历史记录设置
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];
我正在使用 iOS xmpp 框架。 我想在需要时获取房间聊天记录。比如有一个按钮,点击按钮,每次会收到20条历史消息。
如果我有 100 条历史消息,我点击按钮 5 次,然后我将获得所有历史消息。
[xmppRoom1 joinRoomUsingNickname:@"myNickname" history:history password:nil];
此方法只能使用一次
我用这个方法,但是什么都能收到
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>
发送历史记录为零 并在 openfire 中更新 打开你的 openfire url 然后点击群聊 > 群聊设置 > 你的群 > 历史记录设置
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];