From 4279a4acf8d3328b56ec68a870fc2bc597c6226e Mon Sep 17 00:00:00 2001 From: Alex Wenckus Date: Tue, 28 Nov 2006 18:46:40 +0000 Subject: [PATCH] Added ability to create a chat with a prior specified threadID. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@6241 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smack/ChatManager.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/source/org/jivesoftware/smack/ChatManager.java b/source/org/jivesoftware/smack/ChatManager.java index 5bcd6e2fd..23c31571c 100644 --- a/source/org/jivesoftware/smack/ChatManager.java +++ b/source/org/jivesoftware/smack/ChatManager.java @@ -121,11 +121,29 @@ public class ChatManager { * @return the created chat. */ public Chat createChat(String userJID, MessageListener listener) { - String threadID = nextID(); + String threadID; + do { + threadID = nextID(); + } while (threadChats.get(threadID) != null); - Chat chat = createChat(userJID, threadID, true); + return createChat(userJID, threadID, listener); + } + + /** + * Creates a new chat using the specified thread ID, then returns it. + * + * @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 + * @return the created chat. + */ + public Chat createChat(String userJID, String thread, MessageListener listener) { + Chat chat = threadChats.get(thread); + if(chat != null) { + throw new IllegalArgumentException("ThreadID is already used"); + } + chat = createChat(userJID, thread, true); chat.addMessageListener(listener); - return chat; }