AnsweredAssumed Answered

Problem conflict between ChatManagerListener and MessageListener

Question asked by Gustavo on May 20, 2016

Hello everyone,

I really need help, i having serious problem with my app and I  not able to solve it.

 

When I make the login i register a ChatManagerListener to listen every chat and trigger a notification:

 

Here is my ChatManagerListener

 

@Override
public void chatCreated(Chat chat, final boolean createdLocally) {

  if (!createdLocally) {

  if (chat.getParticipant().contains("@conference"))

   return;
   AppDB.getInstance().createChat(new ChatModel(chat)); // store on DB
   chat.addMessageListener(new ChatMessageListener() {

   @Override
   public void processMessage(final Chat chat, final Message message) {

   if (message.getBody() != null) {

// *** HERE I TRIGGER THE NOTIFICATION AND OTHER THINGS.

 

This is working ok, when other part start the chat, the client receive and start notification.

 

 

Now, my code of chat (when the client start chat):

 

newChat = MyXMPP.getChatManager().createChat(destination, myMessageListener);

 

private class MyMessageListener implements ChatMessageListener {

 

   @Override
   public void processMessage(Chat chat, final Message message) {

  if (message.getBody() == null)

   return;
  final ChatMessageModel msg = new ChatMessageModel(message, false);
   runOnUiThread(new Runnable() {

   @Override
   public void run() {

   chatMessageModels.add(msg);
   listAdapter2.notifyDataSetChanged();
   saveMessage(message);
   mRecyclerView.scrollToPosition(listAdapter2.getItemCount() - 1);
   }

  });

 

 

When I start the chat and send a message, the listener that is being called is the ChatManagerListener and not the ChatMessageListener. I see that the server is generating another Thread ID for the messages.

 

I don´t know what is wrong, does anyone can help me?

 

Thanks,

Outcomes