Search code examples
iosxmppxmppframeworknode-xmpp

How to edit name of the existing Group name using XMPP in iOS


Currently i am making chat application and i required to Edit group name.

if any one have solution then please send me because i spend many hours for edit group name but not found any solution.

Thanks


Solution

  • Following iOS XMPPFramework - Room / chat messages history hints (@Moral 's answer) about Persistant room, you have to keep in mind that

    1) Groupchat name, as JID (JabberID) it's unique ID and cannot be changed in any way. So you'll cannot change [email protected]

    2) Groupchat topic (and/or description) can be changed. I can't find a decent tutorial about, however, looking at previous answer, you'll have to add something like that (look point 3):

    -(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"];
            // Change room name
    if ([var isEqualToString:@"muc#roomconfig_roomname"]) {
               [field removeChildAtIndex:0];
               [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"myNewName"]];
           }
           }
        }
        [sender configureRoomUsingOptions:newConfig];
    }
    

    Pay attention: if an user has not the grants to change the room name, you must enable the change name permissions. Again, while sending the form, you have to send before something like

    -(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_changesubject"]) {
               [field removeChildAtIndex:0];
               [field addChild:[NSXMLElement elementWithName:@"value" stringValue:@"true"]];
    // if does not works:         [field addChild:[NSXMLElement elementWithName:@"value" booleanValue:@"true"]];
    
     }
            }
            [sender configureRoomUsingOptions:newConfig];
        }
    

    Look at official spec to understand how Multiuserchat (groupchat) works

    More, this answer about how to configure a MUC may help you XMPPFramework - Implement Group Chat (MUC)