Add ChatManager.createChat(String)

Also some minor refactors in Chat and changes in ChatManager.
This commit is contained in:
Florian Schmaus 2014-12-30 19:55:15 +01:00
parent c5d0fb3c7b
commit d6ab0cf463
2 changed files with 18 additions and 5 deletions

View File

@ -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);
}
/**

View File

@ -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) {