MessageListener Problem and new Chat Thread

Hi guys,

if some kind of new to smack, so don’t kill mie for the first question. I’ve search the forum too, but maybe I didn’t know the right words.

I have a problem with creating a chat. If registered a listener which gets informed if a chat is created. This works very well. Due weak references of a chat object in the chatmanager I added it to a list to have reference. Then I register a message listener, which gets called (sometimes) to receive the first message.

Now the problem is, that everytime a person sends me a message from googletalk, I don’t receive any message with the message listener. I figured out that the chat manager creates a new chat with a different ID. Could that mean that my chat is lost and that’s why there is no listener anymore?

How to resolve this issue?

Any help?

I’ve found the Chat stuff doesn’t end up working like most people want. I just use a PacketListener with a chat filter and sort incoming messages by the base address of the sender. Use StringUtils.parseBareAddress() to get the base address.

Whenever a new chat is created, look up your list for a chat with the participant Id and “reuse” that object - the thread Id can change inbetween messages unfortunately.

Here’s a snippet of how I go about it:

public void chatCreated(Chat chat, boolean createdLocal) {
        // keep track of all sessions
        final ChatSession chatsess = findSessionParticipant(chat.getParticipant());         if (chatsess != null) {
            chatsess.thisChat.removeMessageListener(this);
                        chatsess.thisChat = chat;
            if (chatsess.thisChat.getListeners().isEmpty() ||
                    !chatsess.thisChat.getListeners().contains(this))
                chatsess.thisChat.addMessageListener(this);
            chatsess.showChatGUI();
        } else {
            // create new session
            final ChatSession sess = new ChatSession(chat, appSettings.keepChatLog());
            if (sess.thisChat.getListeners().isEmpty() ||                     !sess.thisChat.getListeners().contains(this))
                sess.thisChat.addMessageListener(this);
            allChats.add(sess);
            sess.showChatGUI();
        }
    }