试试这个代码:
Form form = muc.getConfigurationForm().createAnswerForm();
// Create a new form to submit based on the original form
form.setAnswer("muc#roomconfig_passwordprotectedroom", false);
form.setAnswer("muc#roomconfig_roomname",myMUCName);
form.setAnswer("muc#roomconfig_persistentroom", true);
form.setAnswer("muc#roomconfig_changesubject", true);
form.setAnswer("muc#roomconfig_publicroom",true);
form.setAnswer("muc#roomconfig_allowinvites",true);
form.setAnswer("muc#roomconfig_membersonly",false);
form.setAnswer("muc#roomconfig_moderatedroom",false);
// Sets the new owner of the room
List<String> owners = new ArrayList<String>();
//Be carefull: if members does not exists, it brokes!
owners.add(userName +"@"+"(my local ip or server name placeholder)");
form.setAnswer("muc#roomconfig_roomowners", owners);
// Send the completed form
muc.sendConfigurationForm(form);
System.out.println("MUC is now registered");
muc.join(userName );
现在,如果一切正常,您将以 userName 的身份加入房间,并且 userName 也将成为所有者。
您可以通过编程方式检查 MUC 的所有者
muc.getOwners() //List<Affiliate>, for each Affialiate you'll have to affiliate.getJid().toString()
您可以通过这行代码邀请其他人:
muc.invite(user, "Invite");
然后,如果你想“永远”见到他们,
muc.grantMembership(user);
这样您就可以看到会员资格
muc.getMembers();
请注意:
附属者:MUC 中具有已定义角色(Onwer、Admin、Member、Outcast)的用户
占用者:MUC 中的在线用户
并非所有占用者都可以拥有角色,并非所有附属机构都会自动成为占用者。
此外,您无法确定会员是否加入过群聊。
通量是这样的:
用户 1 创建 Muc
(可选)用户 1 向他想要的任何用户发出 Muc 邀请(例如:用户 2、用户 4)
(可选)用户 1 将 Muc 会员分配给他想要的任何现有用户(例如:用户 3、用户 4)
用户2和用户4在线时将收到接受/拒绝的邀请
User3 和 User4 不会收到任何信息,但他们将在 MUC 中发挥作用。
User2、User3、User4 需要注册提供者以获取 IQ 节,然后每个 MUC 的侦听器接收邀请,另一个接收消息(和/或其他事件)。