接受聊天室邀请 [英] Accepting chatroom invitation

查看:149
本文介绍了接受聊天室邀请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用XMPPFramework创建MUC,并使用以下代码发送用户邀请请求加入该会议室。

I'm able to create a MUC using XMPPFramework and send user invitation requests to join that room by using the code below.

// Creating
AppDelegate *dele =(AppDelegate *) [[UIApplication sharedApplication]delegate];

xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:dele jid:[XMPPJID jidWithString:self.roomName] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom addDelegate:dele delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:dele.xmppStream];
[xmppRoom joinRoomUsingNickname:self.myNick history:nil];

// Inviting
[xmppRoom inviteUser:[XMPPJID jidWithString:@"abc@host"] withMessage:@"Come Join me"];

用户abc如何知道他已收到邀请,他如何回应通过接受还是拒绝?

How does a user "abc" know that he has received an invitation and how can he react to it either by accepting or declining?

我在XMPPFramework中找不到任何直接处理聊天室邀请的课程。
我的研究表明,每当用户收到聊天室邀请时,都会调用xmmppStream的委托方法:

I could not find any class in XMPPFramework which directly deal with chat room invitation. My research says that whenever a user receives an chatroom invitation, xmmppStream's delegate method is called:

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message

在该消息中,我检查是否它包含名称为invite的NSXMLElement,如果包含,则向用户发送回调。然后我创建聊天室,其名称与用户收到邀请的聊天室名称相同,并进入新创建的房间。它工作正常,但安静冗长,不安静有效。
我想知道在XMPPFramework中是否有一个类这里可以处理聊天室邀请分别。例如,检测,接受和拒绝房间邀请。

In that message, I check whether the it contains NSXMLElement with name "invite", and if it contains then i send a callback to the user. Then i create chatroom with the same name as the name of the chatroom from which user received invitation and enter that newly created room. It works fine but quiet lengthy and not quiet efficient. I want to know if there is a class in XMPPFramework available here which could handle chat room invitation separately. For instance, detecting, accepting, and declining of room invitations.

我提取房间名称的代码:

My code for extracting room name:

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
    NSXMLElement * x = [message elementForName:@"x" xmlns:XMPPMUCUserNamespace];
    NSXMLElement * invite  = [x elementForName:@"invite"];
    NSXMLElement * decline = [x elementForName:@"decline"];
    NSXMLElement * directInvite = [message elementForName:@"x" xmlns:@"jabber:x:conference"];
    NSString *msg = [[message elementForName:@"body"]stringValue];
    NSString *from = [[[message attributeForName:@"from"]stringValue];
    if (invite || directInvite)
    {
        [self createAndEnterRoom:from Message:msg];
        return;
    }
    [self.delegate newMessageRecieved:msg];
}


推荐答案

对于房间邀请和拒绝,实施 XMPPMUCDelegate 及其方法 -xmppMUC:didReceiveRoomInvitation: -xmppMUC:didReceiveRoomInvitationDecline:

For room invitations and declines, implement XMPPMUCDelegate and its methods -xmppMUC:didReceiveRoomInvitation: and -xmppMUC:didReceiveRoomInvitationDecline:.

要获得房间JID,请调用 [消息来自] ;

To get the room JID, invoke [message from];

要加入会议室,请实例化 XMPPRoom 并调用 -joinRoomUsingNickname:history:

To join the room, instantiate an XMPPRoom and invoke -joinRoomUsingNickname:history:.

然后让你的房间委托类实现 XMPPRoomDelegate ,并实现一些委托方法来处理房间内的接收消息。

Then have your room delegate class implement XMPPRoomDelegate, and implement some of the delegate methods to handle receiving messages in the room.

看起来目前没有更自动的方式来进行respo nd to invitations。

It looks like there isn't at present a more automatic way to respond to invitations.

更新:委托回调现在接收房间JID作为参数,稍微澄清了语义。

Update: The delegate callbacks now receive the room JID as a parameter, clarifying the semantics a bit.

- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message;
- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitationDecline:(XMPPMessage *)message;

这篇关于接受聊天室邀请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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