我试着用Java创建一个多用户聊天。我使用的是smack库。下面是我创建多用户聊天的代码:
MultiUserChat muc = new MultiUserChat(connection, "roomname@somehost");
muc.create("mynickname");
Form form = muc.getConfigurationForm();
Form submitForm = form.createAnswerForm();
submitForm.setAnswer("muc#roomconfig_roomname", "A nice formatted Room Name");
submitForm.setAnswer("muc#roomconfig_roomdesc", "The description. It should be longer.");
muc.sendConfigurationForm(submitForm);
muc.addMessageListener(mucMessageListener); // mucMessageListener is a PacketListener然后,我尝试使用mucMessageListener捕获上面创建的这个房间发送的消息:
private PacketListener mucMessageListener = new PacketListener() {
public void processPacket(Packet packet) {
if (packet instanceof Message) {
Message message = (Message) packet;
// this is where I got the problem
}
}
}当其他部分(不是该multiuserchat的所有者的用户)接收到消息时,他是否能以某种方式获得上面这行中设置的值:
submitForm.setAnswer("muc#roomconfig_roomname", "A nice formatted Room Name");您看,只获取房间的JID对视图并不是很好。我希望我可以有一个字符串,它的值是“一个不错的格式化房间名称”。
我们怎样才能做到这一点?
发布于 2018-02-28 23:56:14
你可以很容易地从下面的代码中获得它的配置,比如name等:
MultiUserChatManager mucManager = MultiUserChatManager.getInstanceFor(connection);
RoomInfo info = mucManager.getRoomInfo(room.getRoom());现在你可以像这样获得它的信息:
String mucName = info.getName();
Boolean isPersistence = info.isPersistent();等等。
发布于 2014-05-13 14:46:58
在XEP-45 6.4中描述了检索muc#roomconfig_romname的值。Smack提供MultiUserChat.getRoomInfo()方法来执行查询。
RoomInfo roomInfo = MultiUserChat.getRoomInfo(connection, "roomname@somehost.com")
String roomDescription = roomInfo.getDescription()发布于 2016-02-20 05:49:41
如果您想读取var的值,例如,在config中的title of room name
Form form = chat.getConfigurationForm();
String value = form.getField("muc#roomconfig_roomname").getValues().next();然后用价值做任何你想做的事情..
https://stackoverflow.com/questions/23611800
复制相似问题