3

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?

Amri Shodiq
  • 51
  • 1
  • 4

3 Answers3

1

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.

Mahdi Moqadasi
  • 2,029
  • 4
  • 26
  • 52
  • I'm using this code in my app using smack and openfire. Can you tell me what's your error, dear @Nilax? – Mahdi Moqadasi Jul 10 '18 at 07:56
  • I am doing exactly the same. muc.create(Resourcepart.from(nickName)); Form form = muc.getConfigurationForm(); Form submitForm = form.createAnswerForm(); submitForm.setAnswer("muc#roomconfig_persistentroom", true); submitForm.setAnswer("muc#roomconfig_membersonly", true); submitForm.setAnswer("muc#roomconfig_roomdesc", room_desc); muc.sendConfigurationForm(submitForm); Can you please suggest me where I am wrong in setting and getting details? – Nil Jul 10 '18 at 10:05
  • Your code for creating MUC is fine, if you sure that muc is created and you invited some one to it using multiUserChat.invite(...) , then must my code works in invitationReceived() method that already added using mMUCManager.addInvitationListener(...) – Mahdi Moqadasi Jul 10 '18 at 10:51
0

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, "roomname@somehost.com")
String roomDescription = roomInfo.getDescription()
Flow
  • 23,572
  • 15
  • 99
  • 156
0

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..