androidxmppsmackasmack

Android xmpp MUC setting default configuration


Am using the Xabber open source project and am able to create a new group, But it always says: This room is locked from entry until configuration is confirmed. I tried to set a default configuration but it throws me exception: 401 not authorized. Whats exactly the problem.

final MultiUserChat multiUserChat;
        try {
            multiUserChat = new MultiUserChat(xmppConnection, room);
            // CHANAKYA: set default config for the MUC
            // Send an empty room configuration form which indicates that we want
            // an instant room
            try {
                multiUserChat.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
            } catch (XMPPException e) {
                e.printStackTrace();
            }

Solution

  • I was also facing the same error. Here I modified the code and it's work for me. Error 401 is not authorized error when we are calling the any getConfigurationForm(), without joining it.


    multiUserChat.join(nickname, password);
    setConfig(multiUserChat); // Here I am calling submit form
    

    private void setConfig(MultiUserChat multiUserChat) {
    
        try {
            Form form = multiUserChat.getConfigurationForm();
            Form submitForm = form.createAnswerForm();
            for (Iterator<FormField> fields = submitForm.getFields(); fields
                    .hasNext();) {
                FormField field = (FormField) fields.next();
                if (!FormField.Type.hidden.equals(field.getType())
                        && field.getVariable() != null) {
                    submitForm.setDefaultAnswer(field.getVariable());
                }
            }
            submitForm.setAnswer("muc#roomconfig_publicroom", true);
            submitForm.setAnswer("muc#roomconfig_persistentroom", true);
            multiUserChat.sendConfigurationForm(submitForm);
        } catch (Exception e) {
            e.printStackTrace();
        }
    
    }
    

    And now I am able to successfully submit the form without any exception. Hope this will work for you.