3

When i send invitation this function is called but i can't understand what line of code should use for accept invitation*. am trying to create a multi user and multi groups invitation also called did received message function.

- (void)xmppMUC:(XMPPMUC *) sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message 
{ 
}
Pradhyuman Chavda
  • 3,814
  • 4
  • 16
  • 24
Shahbaz Ali
  • 109
  • 2
  • 6
  • my chat Rooms and chatting works fine i tested a user in my app and a xmpp local user on imessages ..both can chat in a group invitation works fine . – Shahbaz Ali Sep 22 '14 at 06:18

3 Answers3

4

This is how you can accept the group invitation. You just need to activate your XMPPMUC protocol as below:

XMPPMUC * xmppMUC = [[XMPPMUC alloc] initWithDispatchQueue:dispatch_get_main_queue()];
[xmppMUC   activate:_xmppStream];
[xmppMUC addDelegate:self delegateQueue:dispatch_get_main_queue()];

To accept incoming invitation for MUC:

- (void)xmppMUC:(XMPPMUC *)sender didReceiveRoomInvitation:(XMPPMessage *)message
{
    NSXMLElement * x = [message elementForName:@"x" xmlns:XMPPMUCUserNamespace];
    NSXMLElement * invite  = [x elementForName:@"invite"];
    if (!isEmpty(invite))
    {
        NSString * conferenceRoomJID = [[message attributeForName:@"from"] stringValue];
        [self joinMultiUserChatRoom:conferenceRoomJID];

    }
}

- (void) joinMultiUserChatRoom:(NSString *) newRoomName
{
    XMPPJID *roomJID = [XMPPJID jidWithString:newRoomName];
    XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
    xmppRoom = [[XMPPRoom alloc]
                initWithRoomStorage:roomMemoryStorage
                jid:roomJID
                dispatchQueue:dispatch_get_main_queue()];
    [xmppRoom activate:[self xmppStream]];
    [xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [xmppRoom joinRoomUsingNickname:@"YOUR NICKNAME" history:nil];
}
Fatima Arshad
  • 350
  • 2
  • 5
  • 2
    Now the latest delegate method is : `-(void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *)roomJID didReceiveInvitation:(XMPPMessage *)message ` . Was stuck for few days on : `- (void)xmppMUC:(XMPPMUC *)sender didReceiveRoomInvitation:(XMPPMessage *)message` . – Bista Apr 16 '15 at 05:30
  • can you please share demo link? – Janak Thakkar Feb 12 '16 at 05:21
  • Is this MUC group ? Do we have to join this group everytime when user become online? – Sonu Apr 19 '16 at 08:37
  • @Fatima Arshad can you please help me here http://stackoverflow.com/questions/38895012/didreceiveinvitation-is-not-being-called-in-xmppframework-and-swift-2 – Usama Sadiq Aug 11 '16 at 11:41
2

to accept the incoming invitation :

- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message
{ XMPPRoom *mu = [[XMPPRoom alloc] initWithRoomStorage:xmpproomMstorage jid:roomJID
                                           dispatchQueue:dispatch_get_main_queue()];

    [mu   activate:xmppStream];
    [mu   addDelegate:self delegateQueue:dispatch_get_main_queue()];

    self.toSomeOne = roomJID;

    [mu activate: self.xmppStream];
    [mu fetchConfigurationForm];
    [mu addDelegate:self delegateQueue:dispatch_get_main_queue()];
    [mu joinRoomUsingNickname:xmppStream.YourJid.user history:nil password:@"Your Password"];
self.toSomeOne = roomJID;
    XMPPPresence *presence = [XMPPPresence presence];
   [[self xmppStream] sendElement:presence];
    [xmppRoster addUser:roomJID  withNickname:roomJID.full];
    [self goOnline];
}
Shahbaz Ali
  • 109
  • 2
  • 6
  • Hello @shahbaz, What is self.toSomeone here ? – Sushil Sharma Apr 17 '15 at 06:48
  • 1
    @Sushil , this method is invoke when some one else invite you for joining any room - (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message {} . and self.toSomeOne = roomJID; . and we have to return accept or decline . for this we need the jid of recipent (same like using phone number for replying or sending message) self.toSomeOne = roomJID; in this line we just setting the recipnt id and we send acception or decline latter in code . i hope you understand else ask again . – Shahbaz Ali Apr 18 '15 at 10:17
  • Thanks @shahbaz, How could i know if user has accepted request or not? I am unable to load data from core data. Like we do in peer-peer chat ,we can retrieve whole chat from coredata. But, in MUC how can we save and retrieve data from core data? – Sushil Sharma Apr 20 '15 at 06:25
  • can you please share demo link? – Janak Thakkar Feb 12 '16 at 05:20
0

In my case I need to use both answers and define self like

@interface XMPPDelegate : NSObject <XMPPMUCDelegate>

Activating XMPPMUC protocol as below:

XMPPMUC * xmppMUC = [[XMPPMUC alloc] 
initWithDispatchQueue:dispatch_get_main_queue()];
[xmppMUC   activate:_xmppStream];
[xmppMUC addDelegate:self delegateQueue:dispatch_get_main_queue()];

Receive join message:

- (void)xmppMUC:(XMPPMUC *)sender roomJID:(XMPPJID *) roomJID didReceiveInvitation:(XMPPMessage *)message
{
    DDLogDebug(@"%@", message);
    XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
    XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:roomMemoryStorage 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:password];
    XMPPPresence *presence = [XMPPPresence presence];
    [[self xmppStream] sendElement:presence];
    [xmppRoster addUser:roomJID  withNickname:roomJID.full];
    [self goOnline];
}
Gusa
  • 551
  • 5
  • 7