3
votes

I tried to create a multiuserchat with Java. I'm using smack library. Here is my code to create multiuserchat:

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

Then, I tried to capture the message sent by this room created above using 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
        }
    }
}

As the message received by other part (the user who is not the owner of this multiuserchat), can he somehow get the value set in this line above:

submitForm.setAnswer("muc#roomconfig_roomname", "A nice formatted Room Name");

You see, getting just the JID of the room is not really good for the view. I expect I could have a String which value is "A nice formatted Room Name".

How can we get that?

3

3 Answers

1
votes

You can easily get its configurations like name and etc from this code:

MultiUserChatManager mucManager = MultiUserChatManager.getInstanceFor(connection);
RoomInfo info = mucManager.getRoomInfo(room.getRoom());

now you can get its informations like this:

String mucName = info.getName();
Boolean isPersistence = info.isPersistent();

and etc.

0
votes

Retrieving the value of muc#roomconfig_romname is described in XEP-45 6.4. Smack provides the MultiUserChat.getRoomInfo() method to perform the query.

RoomInfo roomInfo = MultiUserChat.getRoomInfo(connection, "[email protected]")
String roomDescription = roomInfo.getDescription()
0
votes

If you want to read a value of var for example title name of room in config

Form form = chat.getConfigurationForm();
String value =  form.getField("muc#roomconfig_roomname").getValues().next();

then do what ever you want with value..