3

migrated from asmack to smack 4.1 beta2. The muc rooms created are no longer persistent.

MultiUserChatManager mucm=MultiUserChatManager.getInstanceFor(connection);
muc=mucm.getMultiUserChat(groupid+"@conference.localhost");
DiscussionHistory histroy=new DiscussionHistory();
histroy.setMaxStanzas(10);
muc.createOrJoin(username,null,histroy,SmackConfiguration.getDefaultPacketReplyTimeout());
muc.nextMessage();

when created with gajim, the rooms are persistent.

EDIT : Here is code we used earlier. By default the chat rooms were persistent,

muc = new MultiUserChat(connection, groupid+"@conference.localhost");

if(!muc.isJoined())
{
DiscussionHistory histroy=new DiscussionHistory();
histroy.setMaxStanzas(10);
muc.join(username,null,histroy,SmackConfiguration.getDefaultPacketReplyTimeout());
muc.nextMessage(0);
}
Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44
Vignesh
  • 215
  • 3
  • 10
  • 1
    How did you previously create persistent rooms? I think you need to send the correct data forum using `MultiUserChat.create` to create a persistent room. – Flow Feb 09 '15 at 13:42

4 Answers4

5

You need to set muc#roomconfig_persistentroom to true in the MUC configuration from when creating the room.

MultiuserChat muc = manager.getMultiUserChat("myroom@muc.example.org");
muc.create("myNick");
// room is now created by locked
Form form = muc.getConfigurationForm();
Form answerForm = form.createAnswerForm();
answerForm.setAnswer("muc#roomconfig_persistentroom", true);
muc.sendConfigurationForm(answerForm);
// sending the configuration form unlocks the room

Note that not all XMPP MUC services support persistent rooms. For more information see:

Flow
  • 23,572
  • 15
  • 99
  • 156
  • 1
    I think answerForm.setAnswer("muc#roomconfig_persistentroom", "true"); should be answerForm.setAnswer("muc#roomconfig_persistentroom", true); instead of String a boolean value. – Arun Badole Jan 14 '16 at 09:32
  • @flow what should be placed in replacement of "muc#roomconfig_persistentroom"? – Sakhawat Hossain Sep 29 '20 at 09:58
5

You need to submit form like this for making a persistent group:

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();
    }
}
Spooky
  • 2,966
  • 8
  • 27
  • 41
saurabh dixit
  • 863
  • 6
  • 19
1

In smack 4.1.1, The answers given by @saurabh dixit throw an exception. Please check this thread on ignite website Correct implementation for persistent rooms smack 4.1.1

back2back
  • 113
  • 11
0
        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_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);

This is how you can send the room configuration from and configure room. For more Details please see question. How to send room configuration form and create persistce rooms from android using smack 4.3.4

shekhar pande
  • 1,172
  • 1
  • 11
  • 21