Hi, I have the code below, which adds a chat listener when there is a new chat session created
by a remote ID. However, I find that the chatCreated event is fired for every incoming message
I receive, if the conversation is initiated by the other party. (It only gets fired once if I initiated the
conversation.) This does not sound very efficient because for every incoming message a new Chat
object and a new MessageListener object are created. Am I doing something wrong here? Is there
anyway to reuse an existing Chat and MessageListener object in this case? Thanks!
ChatManager chatmanager = connection.getChatManager();
chatmanager.addChatListener(new ChatManagerListener() {
public void chatCreated(Chat chat, boolean createdLocally) {
System.out.println("chatCreated " + chat.getParticipant() + " " + chat.getListeners());
if (!createdLocally) {
chat.addMessageListener(new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message.getBody());
}
});
}
}
});