iOS XMPPFramework - 房间/聊天消息历史记录 [英] iOS XMPPFramework - Room / chat messages history

查看:37
本文介绍了iOS XMPPFramework - 房间/聊天消息历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XMPPFramework

加入现有房间后如何接收消息历史记录?

现在我加入这样的房间:

Now i join to room like this:

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

我还阅读了 文档

根据这个例子,我也尝试通过这种方式加入房间:

According to this example I also tried to join room this way:

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:@"bob@%@",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]; 

我成功加入房间,但没有收到以前的消息历史记录.

I join room successfully, but don't receive history of previous messages.

顺便说一句,如果房间里至少有一个用户,我会收到所有以前的消息,即使我加入房间,如:

Btw, if at least one user in the room, i receive all previous messages, even if i join room like:

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

如果所有用户都离开房间然后一些人再次加入 - 历史记录为空=(

If all users leave room and then some join again - history is empty=(

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

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

And some questions about example from documentation:

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

id"参数是什么意思?我在文档中没有找到任何说明.

推荐答案

当您创建了一个房间并加入时,您需要配置该房间以使其持久化,这意味着什么那是:

When you've created a room and you've joined, you need to configure that room to make persistent, what this means is that:

永久房间如果最后一个居住者离开,房间不会被破坏;反义词:临时房间.(你想要这个房间的配置).

Persistent Room A room that is not destroyed if the last occupant exits; antonym: Temporary Room. (You want this room's configuration).

临时房间如果最后一个居住者离开,房间就会被摧毁;反义词:持久房间.

Temporary Room A room that is destroyed if the last occupant exits; antonym: Persistent Room.

1.因此,您创建并加入了一个房间.

1. So, you create and join a room.

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;(仅当一切顺利时),您必须配置您的房间

2. Then, the delegate method xmppRoomDidJoin:sender; is called (only if all has gone right), and you have to configure your room

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

fetchConfigurationForm 方法发送 IQ 以请求初始房间配置表单.

fetchConfigurationForm method send an IQ to request an initial room configuration form.

已发送到 XMPP 服务器的 IQ 示例:

Example of IQ that has been sent to XMPP Server:

<iq from='crone1@shakespeare.lit/desktop'
    id='create1'
    to='coven@chat.shakespeare.lit'
    type='get'>
  <query xmlns='http://jabber.org/protocol/muc#owner'/>
</iq>

3. 当 XMPP 服务器回答房间配置时,-xmppRoom:sender didFetchConfigurationForm:configForm;方法被调用.您可以在此处更改房间的默认值,使其成为持久、房间名称、仅限成员等.

3. When XMPP server answer with the room configuration the -xmppRoom:sender didFetchConfigurationForm:configForm; method is called. And here is where you change the default values of the room to make persistent, room name, members only, etc.

示例:

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

这篇关于iOS XMPPFramework - 房间/聊天消息历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆