3

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

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

4 回答 4

5

您需要在创建房间时在 MUC 配置中设置muc#roomconfig_persistentroom为。true

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

请注意,并非所有 XMPP MUC 服务都支持持久房间。有关更多信息,请参阅:

于 2015-02-10T15:56:46.503 回答
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();
    }
}
于 2015-03-03T05:45:53.160 回答
1

在 smack 4.1.1 中,@saurabh dixit 给出的答案抛出异常。请在 ignite 网站上查看此线程持久房间 smack 4.1.1 的正确实施

于 2015-08-03T14:40:13.057 回答
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);

这是您可以发送房间配置和配置房间的方式。有关更多详细信息,请参阅问题。 如何使用 smack 4.3.4 从 android 发送房间配置表单并创建持久房间

于 2019-12-31T06:02:41.813 回答