powered by Jive Software

Smack 3.1.0 creates a new chat for every incoming message

Hi *!

I’m trying Smack 3.1.0, and I’m quite impressed, making a jabber rhino REPL in something like half hour.

However, I’ve found a bug which took a few hours to figure out:

If the remote client doesn’t supply a thread-id (psi doesn’t), then Smack will create a new Chat for every thread. It can’t ever reuse chats from ChatManager.jidChats because of an impedance mismatch.

The problem is, it puts raw jabber addresses as keys (foo@bar.org/Client), but gets jabber addresses cleaned by StringUtils.parseBareAddress (foo@bar.org)

The following patch fixes the problem:

`--- ../smack_src_3_1_0/source/org/jivesoftware/smack/ChatManager.java   2008-11-21 08:31:48 +0300
+++ source/org/jivesoftware/smack/ChatManager.java      2009-01-22 17:30:49 +0300
@@ -102,13 +102,13 @@
                 Message message = (Message) packet;
                 Chat chat;
                 if (message.getThread() == null) {
-                    chat = getUserChat(StringUtils.parseBareAddress(message.getFrom()));
+                    chat = getUserChat(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()));
+                        chat = getUserChat(message.getFrom());
                     }
                 } `

P.S. The HTML editor is kind of creepy, having no fallback to plain HTML. It doesn’t work in Konqueror at all, so I had to fire Firefox :frowning:

Seeing the same problem. How are issues created at igniterealtime?

I will check you patch, Ilja, thanks for analysing this.

Martin.

The patch works fine for me.

Hi,

I am experiencing the same problem with the ChatManager, and the patch works perfectly for me also.

But, since this is quite a big bug for the ChatManager object, I was wondering what was Ignite position on this bug ?

  1. Is there a bug number associated to this issue ? If not, is it possible to create one ?

  2. Is this issue fixed in a beta version ? If not, is there a plan to include this patch in a future version ?

Thanks,

BTW, Smack is an amazing library very easy to use ! Great work !

Philippe

How do I go about applying this patch? I think this might be the problem I’m having…

Well, download the source, unpack, apply patch with patch(1) utility,

using an IDE, or by hand, and compile it with ant.

2009/3/18, mikekbrad igniterealtime@jivesoftware.com:

Илья Казначеев,

A new message was posted in the thread "Smack 3.1.0 creates a new chat for

every incoming message":

http://www.igniterealtime.org/community/message/189114#189114

Author : mikekbrad

Profile : http://www.igniterealtime.org/community/people/mikekbrad

Message:

According to the JIRA instance for smack http://www.igniterealtime.org/issues/browse/SMACK you should post bugs here on the forums and a developer will create a JIRA issue. This does not seem to be happening.

Bug filed under http://www.igniterealtime.org/issues/browse/SMACK-269

I had a look, and found that the original code is most likely to match the bare JID against full JIDs in a map. This makes getting successful matches more unlikely. I’ve applied the patch to Smacks trunk. It will be part of the next release.

With the patch that you have applied there is a problem if smack creates a chat for a user with a bare jid user@server.com. If the user replies without a thread id and a full jid in the from attribute user@server.com/res, a new chat will be created. Smack should check if a a chat with the bare jid exists and deliver the message to it.

I have attached a little patch to fix this.

`

--- smack_src_3_1_0/source/org/jivesoftware/smack/ChatManager.java     2010-02-23 19:27:26.000000000 +0100
+++  source/org/jivesoftware/smack/ChatManager.java    2010-02-23  19:37:47.000000000 +0100
@@ -111,7 +111,9 @@
                          chat = getUserChat(message.getFrom());
                     }
                  }
-
+        if (chat == null) {
+                    chat =  getUserChat(StringUtils.parseBareAddress(message.getFrom()));
+         }
                 if(chat == null) {
                     chat =  createChat(message);
                 }

`

chat_manager.patch.zip (387 Bytes)

Fixed in 3.2 Beta 2.