2

Using xmpp I can able to create group and send invitation to friends but while I send message on group, members will never received that message.

Is member have to accept the invitation ? If yes, then let me know how?

Please refer below code and if I made any mistake or still I am missing any things then guide me for that so after I can send and receive messages in group and chat with friends.

Below I'm attaching my some code snippet for create group in xmpp and send message.

[self setUpRoom:[NSString stringWithFormat:@"%@@conference.myserver",@"GroupName"]];


-(void)setUpRoom:(NSString *)ChatRoomJID {

    // Configure xmppRoom
    XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];

    XMPPJID *roomJID = [XMPPJID jidWithString:ChatRoomJID];

    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:_ro(@"LoginNumber")
                            history:nil
                           password:nil];

    [self performSelector:@selector(ConfigureNewRoom:) withObject:nil afterDelay:4];

}

Now for room confirmation i used this snippet

- (void)ConfigureNewRoom:(id)sender
{
    [xmppRoom configureRoomUsingOptions:nil];
    [xmppRoom fetchConfigurationForm];
    [xmppRoom fetchBanList];
    [xmppRoom fetchMembersList];
    [xmppRoom fetchModeratorsList];

}

XMPPRoom Delegate Mothods

- (void)xmppRoomDidCreate:(XMPPRoom *)sender
{
    DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);

   // I am inviting friends after room is created

    for (int i = 0; i<[self.friendListArray count]; i++)
    {
        NSString * tempStr=[NSString stringWithFormat:@"%@@myserver",[[self.friendListArray objectAtIndex:i] valueForKey:@"UserNumber"]];
        [sender inviteUser:[XMPPJID jidWithString:tempStr] withMessage:@"Greetings!"];
    }

}

- (void)xmppRoomDidJoin:(XMPPRoom *)sender
  {
        DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);

        NSLog(@"........Room Did join.......");
  }

- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm
   {
        DDLogInfo(@"%@: %@", THIS_FILE, THIS_METHOD);

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

            if ([var isEqualToString:@"roomconfig_enablelogging"])
            {

                [field removeChildAtIndex:0];
                [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"1"]];
            }

            if ([var isEqualToString:@"muc#roomconfig_maxusers"])
            {

                [field removeChildAtIndex:0];
                [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"100"]];
            }


        }
        [sender configureRoomUsingOptions:newConfig];
  }

Sending message in group on button click for testing purpose

-(void)sendGroupMessage
{
    [xmppRoom sendMessageWithBody:@"Hi All"];

    NSXMLElement *x = [NSXMLElement elementWithName:@"groupchat" xmlns:XMPPMUCNamespace];

    XMPPMessage *message = [XMPPMessage message];
    [message addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"%@/%@",[xmppRoom.roomJID full],_ro(@"LoginNumber")]];
    [message addChild:x];
    NSLog(@"x in Invite === %@",x);
    [xmppStream sendElement:message];
}
Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
Harin
  • 867
  • 11
  • 23

2 Answers2

2

Instead of:

 [xmppStream sendElement:message]

try:

 [xmppRoom sendMessage:message]
0

For MUC chat the member has to accept the invitation. You can find the answer here:

https://stackoverflow.com/a/26031897/4050160

Community
  • 1
  • 1
Fatima Arshad
  • 350
  • 2
  • 5