In the process of creating a simple bot using Smack I have encountered a problem for which a patch has been submitted below. Could someone please make sure that the deveopers see this?
It appears that when a chat without threadID is initiated with a bot written with Smack, Smack goes ahead and invents a thread ID. Meanwhile in ChatManager.java it is clear that both threaded and nonthreaded chats should be handled (threadChats, jidChats). It should just be accepting chats without thread id’'s right?
As a result of how it works now, this little bit of decision logic does what you might not expect. A new chat is created every time.
Chat chat;
if (message.getThread() == null) {
chat = getUserChat(StringUtils.parseBareAddress(message.getFrom()));
}
else {
chat = getThreadChat(message.getThread());
if (chat == null) {
// Try to locate the chat based on the sender of the message
chat = getUserChat(StringUtils.parseBareAddress(message.getFrom()));
}
}
if(chat == null) {
chat = createChat(message);
}
Clearly upon initiating a chat the ID can be invented, but not upon receiving a chat, because the result is that every new message received in an externally initiated chat appears to Smack to be a whole new thread!
Index: source/org/jivesoftware/smack/ChatManager.java
===================================================================
— source/org/jivesoftware/smack/ChatManager.java (revision 8394)
+++ source/org/jivesoftware/smack/ChatManager.java (working copy)
@@ -159,7 +159,9 @@
private Chat createChat(String userJID, String threadID, boolean createdLocally) {
Chat chat = new Chat(this, userJID, threadID);
-
threadChats.put(threadID, chat);
-
if (threadID != null) {
-
threadChats.put(threadID, chat);
-
}
jidChats.put(userJID, chat);
for(ChatManagerListener listener : chatManagerListeners) {
@@ -171,9 +173,6 @@
private Chat createChat(Message message) {
String threadID = message.getThread();
-
if(threadID == null) {
-
threadID = nextID();
-
}
String userJID = message.getFrom();
return createChat(userJID, threadID, false);
Message was edited by: fluxe1963