Unable to create persistent room with Smack 4.2.4

Hi Team,
I am unable to create a persistent room with below code snippet.

String groupServiceName = “goupName@conference.domainName”;
try{
// Get the MultiUserChatManager
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
// Create a MultiUserChat using an XMPPConnection for a room
MultiUserChat multiUserChat = manager.getMultiUserChat(JidCreate.entityBareFrom(groupServiceName));
// Create the room
multiUserChat.create(Resourcepart.from(“John”));
// Get the the room’s configuration form
Form form = multiUserChat.getConfigurationForm();
// Create a new form to submit based on the original form
Form submitForm = form.createAnswerForm();
// Add default answers to the form to submit
for (Iterator fields = form.getFields().iterator(); fields.hasNext():wink: {
FormField field = (FormField) fields.next();
if (!FormField.Type.hidden.equals(field.getType()) && field.getVariable() != null) {
// Sets the default value as the answer
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer(“muc#roomconfig_roomname”, “GroupB”);
submitForm.setAnswer(“muc#roomconfig_roomdesc”, “This is a Test Group”);
submitForm.setAnswer(“muc#roomconfig_publicroom”, true);
submitForm.setAnswer(“muc#roomconfig_persistentroom”, true);
submitForm.setAnswer(“x-muc#roomconfig_canchangenick”, true);
submitForm.setAnswer(“x-muc#roomconfig_registration”, true);

        multiUserChat.sendConfigurationForm(submitForm);
    }
    catch (XmppStringprepException xse){
          xse.printStackTrace();
    }
    catch (SmackException.NoResponseException nre){
        nre.printStackTrace();
    }
    catch (XMPPException.XMPPErrorException xee){
        xee.printStackTrace();
    }
    catch (MultiUserChatException.MucAlreadyJoinedException mucaje){
        mucaje.printStackTrace();
    }
    catch (SmackException.NotConnectedException nce){
        nce.printStackTrace();
    }
    catch (MultiUserChatException.MissingMucCreationAcknowledgeException mmcae){
        mmcae.printStackTrace();
    }
    catch (MultiUserChatException.NotAMucServiceException namse){
        namse.printStackTrace();
    }
    catch(InterruptedException ie){
        ie.printStackTrace();
    }

And I am verifying persistent of the aforementioned room from Open Fire Admin Console, any suggestion will be helpful.
Thanks

Can you give some more information, like what exactly doesn’t work, any exceptions that are thrown, or stanza logs?

Hi Paul,
Thanks for the quick reply. Please find the attached documents for stanza reference along with the screenshot of Open Fire MUC room summary which indicates that the created room is not of persistent type. Also, there was no exception in the log.

stanza_logs.txt (8.5 KB)

I’m not an expert in MUC related stuff, but the fact, that Openfire responded with an to the configure form suggests, that the room is in fact persistent. You could try to query the room config in Smack after configuring the room to see, if it is persistent.

Where in the screenshot exactly is this indicated?

@Paul_Schaub
I checked the configuration details of the room and I get the following info:
Room Name: GroupB
Room Desc: This is a Test Group
Is Room Persistent: false

We can see that except persistent attribute all other attributes are in place and please find the attached document which distinguishes the room created from Smack API(GroupB) and another one is created from Open Fire Admin Console(groupx).

Hi rohit.pandey, i’m facing the same problem.

Did you fix it?

Thanks.

Hi @rohit.pandey i found a workaround.

I tried:
answerForm.getField(“muc#roomconfig_persistentroom”).addValue(“1”);|

instead of

answerForm.setAnswer(“muc#roomconfig_persistentroom”, true);

and it works fine. It’s a thing to Smack developers work.

1 Like
       multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
       
        multiUserChat = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(roomJID));

        multiUserChat.create(Resourcepart.from(nickname));

        Form form = multiUserChat.getConfigurationForm();
        Form submitForm = form.createAnswerForm(); submitForm.getField("muc#roomconfig_publicroom").addValue("1");
        submitForm.getField("muc#roomconfig_enablelogging").addValue("1");
        submitForm.getField("x-muc#roomconfig_reservednick").addValue("0");
        submitForm.getField("x-muc#roomconfig_canchangenick").addValue("0");
        submitForm.getField("x-muc#roomconfig_registration").addValue("0");
        submitForm.getField("muc#roomconfig_passwordprotectedroom").addValue("0");
        submitForm.getField("muc#roomconfig_roomname").addValue(roomName);
        submitForm.getField("muc#roomconfig_whois").addValue("participants");
        submitForm.getField("muc#roomconfig_membersonly").addValue("1");
        submitForm.getField("muc#roomconfig_persistentroom").addValue("1");
        multiUserChat.sendConfigurationForm(submitForm);

      I tried above thing and it works for me

[Link How to send room configuration form and create persistce rooms from android using smack 4.3.4 ](https://stackoverflow.com/questions/59540196/how-to-send-room-configuration-form-and-create-persistce-rooms-from-android-usin/59540197#59540197)