ChatMessageListener and Pubsub

HI,

I’ve wrote a software that uses smack API and Openfire for XMPP communication. Currently I’m using both the last version of the Smack library (3.4.1) and the last version of Openfire (3.9.1).

I need to use both the chat and the pubsub services. For this reason, in my code I have something similiar to this snippet of code (taken from the API documentation) for the chat:

ChatManager chatmanager = connection.getChatManager().addChatListener(
    new ChatManagerListener() {
        @Override
        public void chatCreated(Chat chat, boolean createdLocally)
        {
            if (!createdLocally)
                chat.addMessageListener(new MyNewMessageListener());;
        }
    });

and this snippet of code (I’ve omitted something for brevity) for the Pubsub:

final PubSubManager pubSubManager = new PubSubManager(connection,pubsubService);
final InItemEventCoordinator handler = new InItemEventCoordinator("name");
Node node = pubSubManager.getNode(nodeName);
node.addItemEventListener(handler);

where ItemEventCoordinator implements ItemEventListener:

public abstract class ItemEventCoordinator implements ItemEventListener<Item> {      public void handlePublishedItems(final ItemPublishEvent items) {
               // do something
     }
}

Now, in my opinion, in this situation, I have to receive in MyNewMessageListener (method processMessage) the chat messages and in the ItemEventCoordinator (method handlePublishedItems) I have to receive the pubsub notification.

Instead when a publisher publishes a new event on the node, I receive that event in the ItemEventListener, but in the same time also the chatCreated method is called, and from then on all the events published on the node are received both in the handlePublishedItems method of ItemEventCoordinator AND in the processMessage method.

Now, I have to questions:

  1. Is it correct that the chatCreated is called when a new pubsub event is sent? In my opinion no, the pubsub events are Messages, but not messages of type Chat…

  2. Is there a simple way to filter the pubsub events, so that you can receive the chat messages in the MaNewMessageListener and the pubsub events in the ItemEventCoordinatoor? Or the only way is to avoid to use the Chat and Pubsub API, and to use custom packet listeners applied on the connection?

Thanks in advance,

Davide

  1. Is it correct that the chatCreated is called when a new pubsub event is sent? In my opinion no, the pubsub events are Messages, but not messages of type Chat…

No. This is a long-living bug in Smack, which unfortunetaly has only be resolved since 3.4.0 with a workaround instead of real bug fix.

As far as I understand you have to explicitly call:

setNormalIncluded(false) on the ChatManager.

Still, by default, ChatManager also processes “normal” messages (your pubsub messages).

I’ve had my problems, too with that, since 2012: ChatManager listens to messages with type="normal" - #2 by CSH - Smack Dev - Ignite Realtime Community Forums

See SMACK-387

Thanks for the rapid answer!

You are right, with that workaround, the pubsub messages are received only by the ItemEventListener.

Thanks again,

Davide