powered by Jive Software

Enhancement to Smack 1.4.1 MultiUserChat sendMessage(Message) method

Hi,

I would like to recommend changing the sendMessage(Message) method in the MultiUserChat method to the following (around line 1458 of MultiUserChat.java):

public void sendMessage(Message message) throws XMPPException {

message.setTo(room);

message.setType(Message.Type.GROUP_CHAT);

connection.sendPacket(message);

}

(basically, adding the setTo() and setType() calls before sending the packet over the connection).

The idea being that right now you could do the following:

MultiUserChat chat;

//initialize, etc…

Message msg = new Message();

msg.setBody(“Hi guys”);

chat.sendMessage(msg);

And you just get a silent failure. In order for the message to show up, you must create the message like so:

Message msg = new Message(room, Message.Type.GROUP_CHAT);

which works fine, but should be unnecessary.

I guess the a problem might arise if the Message object that you create already has a different type or to value set, but this usage scenario doesn’'t make any sense… so perhaps an alternative would be to have the sendMessage(Message) method throw an XMPPException if the to/type values are not already set correctly (though I think the above approach is much better).

John

P.S. I would’‘ve just added this to the issue tracker but I couldn’‘t find the right place to submit a new issue – am I stupid or is this functionality not available to non-developers? (I created an account in jira but it didn’'t seem to help).