diff --git a/smack-core/src/main/java/org/jivesoftware/smack/Chat.java b/smack-core/src/main/java/org/jivesoftware/smack/Chat.java index 856c5a0fb..f8a6afe58 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/Chat.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/Chat.java @@ -19,6 +19,7 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.util.StringUtils; import java.util.Set; import java.util.Collections; @@ -49,6 +50,9 @@ public class Chat { * @param threadID the thread ID to use. */ Chat(ChatManager chatManager, String participant, String threadID) { + if (StringUtils.isEmpty(threadID)) { + throw new IllegalArgumentException("Thread ID must not be null"); + } this.chatManager = chatManager; this.participant = participant; this.threadID = threadID; @@ -89,10 +93,9 @@ public class Chat { * @throws NotConnectedException */ public void sendMessage(String text) throws XMPPException, NotConnectedException { - Message message = new Message(participant, Message.Type.chat); - message.setThread(threadID); + Message message = new Message(); message.setBody(text); - chatManager.sendMessage(this, message); + sendMessage(message); } /** diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ChatManager.java b/smack-core/src/main/java/org/jivesoftware/smack/ChatManager.java index 71bb7b8ad..fddfb7b5d 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ChatManager.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ChatManager.java @@ -202,7 +202,17 @@ public class ChatManager extends Manager{ * Creates a new chat and returns it. * * @param userJID the user this chat is with. - * @param listener the listener which will listen for new messages from this chat. + * @return the created chat. + */ + public Chat createChat(String userJID) { + return createChat(userJID, null); + } + + /** + * Creates a new chat and returns it. + * + * @param userJID the user this chat is with. + * @param listener the optional listener which will listen for new messages from this chat. * @return the created chat. */ public Chat createChat(String userJID, ChatMessageListener listener) { @@ -214,7 +224,7 @@ public class ChatManager extends Manager{ * * @param userJID the jid of the user this chat is with * @param thread the thread of the created chat. - * @param listener the listener to add to the chat + * @param listener the optional listener to add to the chat * @return the created chat. */ public Chat createChat(String userJID, String thread, ChatMessageListener listener) {