首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何读取MultiUserChat的配置?

如何读取MultiUserChat的配置?
EN

Stack Overflow用户
提问于 2014-05-12 22:31:54
回答 3查看 1.4K关注 0票数 3

我试着用Java创建一个多用户聊天。我使用的是smack库。下面是我创建多用户聊天的代码:

代码语言:javascript
复制
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捕获上面创建的这个房间发送的消息:

代码语言:javascript
复制
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的所有者的用户)接收到消息时,他是否能以某种方式获得上面这行中设置的值:

代码语言:javascript
复制
submitForm.setAnswer("muc#roomconfig_roomname", "A nice formatted Room Name");

您看,只获取房间的JID对视图并不是很好。我希望我可以有一个字符串,它的值是“一个不错的格式化房间名称”。

我们怎样才能做到这一点?

EN

回答 3

Stack Overflow用户

发布于 2018-02-28 23:56:14

你可以很容易地从下面的代码中获得它的配置,比如name等:

代码语言:javascript
复制
MultiUserChatManager mucManager = MultiUserChatManager.getInstanceFor(connection);
RoomInfo info = mucManager.getRoomInfo(room.getRoom());

现在你可以像这样获得它的信息:

代码语言:javascript
复制
String mucName = info.getName();
Boolean isPersistence = info.isPersistent();

等等。

票数 1
EN

Stack Overflow用户

发布于 2014-05-13 14:46:58

XEP-45 6.4中描述了检索muc#roomconfig_romname的值。Smack提供MultiUserChat.getRoomInfo()方法来执行查询。

代码语言:javascript
复制
RoomInfo roomInfo = MultiUserChat.getRoomInfo(connection, "roomname@somehost.com")
String roomDescription = roomInfo.getDescription()
票数 0
EN

Stack Overflow用户

发布于 2016-02-20 05:49:41

如果您想读取var的值,例如,在config中的title of room name

代码语言:javascript
复制
Form form = chat.getConfigurationForm();
String value =  form.getField("muc#roomconfig_roomname").getValues().next();

然后用价值做任何你想做的事情..

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23611800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档