2015-02-09 88 views
0

从asmack迁移到smack 4.1 beta2。 创建的muc房间不再持久。如何创建持久的muc房间中的smack 4.1 beta2

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(); 

用gajim创建时,房间是持久的。

编辑:这是我们以前使用的代码。默认情况下,聊天室呈持续性,

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); 
} 
+1

您以前是如何创建持久性房间的?我认为你需要使用'MultiUserChat.create'发送正确的数据论坛来创建一个持久空间。 – Flow 2015-02-09 13:42:45

+0

你好@flow请检查编辑的问题。 – Vignesh 2015-02-10 06:27:54

回答

3

您需要设置muc#roomconfig_persistentroomtrue在MUC配置从当创建房间。

MultiuserChat muc = manager.getMultiUserChat("[email protected]"); 
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 

请注意,并非所有的XMPP MUC服务都支持持久性会议室。欲了解更多信息,请参阅:

+1

我认为answerForm.setAnswer(“muc#roomconfig_persistentroom”,“true”);应该是answerForm.setAnswer(“muc#roomconfig_persistentroom”,true);而不是String一个布尔值。 – AB1209 2016-01-14 09:32:44

5

您需提交像这样把一个持久组:

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(); 
    } 
}