2015-02-08 140 views
1

我正在开发使用XMPPFramework的iOS XMPPFramework - 房/聊天消息历史

怎样才能收到邮件的历史加入现有的后室聊天应用程序?

现在我加入到房间是这样的:

XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",systemName,xmppServer]]; 
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[XMPPRoomHybridStorage sharedInstance] jid:roomJid]; 
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()]; 
[xmppRoom activate:xmppStream]; 
NSXMLElement *history = [NSXMLElement elementWithName:@"history"]; 
[history addAttributeWithName:@"maxstanzas" stringValue:@"100"]; 
[xmppRoom joinRoomUsingNickname:user.deviceUUID history:history]; 

而且我从documentation

读例如根据这个例子,我也想加入房间是这样的:

XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",systemName,xmppServer]]; 
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[XMPPRoomHybridStorage sharedInstance] jid:roomJid]; 
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()]; 
[xmppRoom activate:xmppStream]; 

NSXMLElement *presence = [NSXMLElement elementWithName:@"presence"]; 
[presence addAttributeWithName:@"from" stringValue:[NSString stringWithFormat:@"[email protected]%@",xmppServer]]; 
[presence addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@@conference.%@/%@",systemName,xmppServer,user.deviceUUID]]; 

NSXMLElement *x = [NSXMLElement elementWithName:@"x" xmlns:@"http://jabber.org/protocol/muc"]; 

NSXMLElement *history = [NSXMLElement elementWithName:@"history"]; 
[history addAttributeWithName:@"maxstanzas" stringValue:@"100"]; 

[x addChild:history]; 

[presence addChild:x]; 

[xmppRoom joinRoomUsingNickname:user.deviceUUID history:presence]; 

我成功加入会议室,但没有收到以前消息的历史记录。

顺便说一句,如果在室内至少一个用户,我收到所有以前的消息,甚至如果我加入房间,如:

[xmppRoom joinRoomUsingNickname:user.deviceUUID history:nil]; 

如果所有用户离开房间,然后一些再加入 - 历史空=(

我在做什么错? 我是否需要开启一些设置在服务器端保存历史(如日志记录)?

和一些关于文档示例的问题:

什么意思是“from”参数?这是否意味着我只从用户bob那里询问这个房间的消息历史?如果我想接收所有历史记录(来自任何用户的消息),该怎么办?

什么意思是“id”参数?我没有在文档中找到任何描述。

回答

3

当你已经创建了一个房间,并已加入,您需要配置空间去持续,这是什么意思是:

持久房 一个房间,是不是如果最后一名乘客退出,则销毁;反义词:临时室。 (你想要这个房间的配置)。

临时房间 如果最后一位居住者退出,房间会被毁坏;反义词:持久的房间。

1.所以,你创建并加入一个房间。

XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",systemName,xmppServer]]; 
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[XMPPRoomHybridStorage sharedInstance] jid:roomJid]; 
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()]; 
[xmppRoom activate:xmppStream]; 
[xmppRoom joinRoomUsingNickname:user.deviceUUID history:history]; 

2.然后,委托方法xmppRoomDidJoin:sender;被调用(仅当所有已经右),你必须配置你的房间

-(void)xmppRoomDidJoin:(XMPPRoom *)sender { 
    NSLog("I did join."); 
    [sender fetchConfigurationForm]; 
} 

fetchConfigurationForm方法发送智商请求最初的房间配置形式。智商

例已被发送到XMPP服务器:

<iq from='[email protected]/desktop' 
    id='create1' 
    to='[email protected]' 
    type='get'> 
    <query xmlns='http://jabber.org/protocol/muc#owner'/> 
</iq> 

当与房间配置XMPP服务器的答案-xmppRoom:sender didFetchConfigurationForm:configForm; 方法被调用。 这里是你改变房间的默认值,再接再厉,房间名称,成员只有等

例子:

-(void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm { 
    NSXMLElement *newConfig = [configForm copy]; 
    NSArray *fields = [newConfig elementsForName:@"field"]; 
    for (NSXMLElement *field in fields) { 
     NSString *var = [field attributeStringValueForName:@"var"]; 
     // Make Room Persistent 
     if ([var isEqualToString:@"muc#roomconfig_persistentroom"]) { 
      [field removeChildAtIndex:0]; 
      [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]]; 
     } 
    } 
    [sender configureRoomUsingOptions:newConfig]; 
} 
+0

感谢您的回复,我今天会尝试 – stsmkrv 2015-02-12 08:29:45

+0

让我知道,这对我有用! – Moral 2015-02-12 21:15:57

1

感谢@Moral的说明。 但在我的情况下,解决方案非常简单。

在在模块睦配置ejabberd.yml刚刚添加默认选项聊天服务器:

mod_muc: ## host: "conference.HOST" 
db_type: odbc 
access: muc 
access_create: muc_create 
access_persistent: muc_create 
access_admin: muc_admin 
min_message_interval: 1.0 
min_presence_interval: 5.0 
default_room_options: 
logging: true 
persistent: true 

以及App加入房间是这样的:

XMPPJID *roomJid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@conference.%@",systemName,xmppServer]]; 
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:[XMPPRoomHybridStorage sharedInstance] jid:roomJid]; 
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()]; 
[xmppRoom activate:xmppStream]; 
NSXMLElement *history = [NSXMLElement elementWithName:@"history"]; 
[history addAttributeWithName:@"maxstanzas" stringValue:@"100"]; 
[xmppRoom joinRoomUsingNickname:user.deviceUUID history:history]; 

完蛋了!