我创建了一个群聊的空间。我已成功创建了组并添加了成员,但问题是组中的成员没有持久化。刷新后组成员会自动删除。
代码:
代码:生成jabber id
private MultiUserChat getMultiUserChat("123456789"){
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(getXmppConnection());
String jid = "123456789@conference.188.202.110.17";
return manager.getMultiUserChat(jid);
}
代码:创建并加入房间
public void createReservedRoom(Context context, String jidName, String roomName, String nickName){
try {
connect();
MultiUserChat muc = getMultiUserChat(jidName);
muc.create(nickName);
try {
//PreferenceUtils.setObject(context, muc, PreferenceUtils.MUC_OBJ);
}catch (Exception e){
e.printStackTrace();
}
Form form = getForm(muc, roomName);
// Send the completed form
muc.sendConfigurationForm(form);
muc.join(nickName);
}catch (Exception e){
e.printStackTrace();
}
}
代码:创建空间
private Form getForm(MultiUserChat muc, String roomName){
Form form = null;
try {
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", roomName);
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",true);
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 brakes!
owners.add("123456789@conference.188.202.110.17");
form.setAnswer("muc#roomconfig_roomowners", owners);
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (NotConnectedException e) {
e.printStackTrace();
}
return form;
}
答案 0 :(得分:0)
群聊不支持&#34;成员&#34;。
群聊可以有占用者(实际上是在群聊中加入会话的人)和附属机构,具有特定角色的用户(所有者,管理员,成员和流出者)。
成为&#34;会员&#34;基本上是指您不是聊天的主持人(管理员)。但我认为你基本上希望你添加的每个人自动加入以下会话中的给定群聊,所以你的用户必须订阅群聊。
如果你在群聊中也想要类似WhatsApp的人,你可以通过给予所有&#34; admin&#34;来模拟。联属或检索给定群聊的所有订阅。这是一个很大的话题......