powered by Jive Software

How to filter <composing/> and <pause/> notifications

I have implelemnted a PacketListener, this is what I am using:

PacketFilter filter = new PacketTypeFilter(Message.class);
xmppConnection.addPacketListener(this, filter);

However I get notifications when someone starts typing. How do I filter the events so that I only get notified when I received a message.

Hi Puneet,

Have a look at the following packages:

**org.jivesoftware.smackx.ChatState**
**org.jivesoftware.smackx.ChatStateManager**
**org.jivesoftware.smackx.packet.ChatStateExtension**

So, assuming you want to just filter out (and ignore?) incoming chatstate related message packets, you would need to do something along the lines of (this is very much psuedo-code... no idea if it even compiles but it will hopefully give you the rough idea)

public void processMessage( Chat chat, Message message )
{
    

** ChatStateExtension** packetExtension = message.getPacketExtension(“http://jabber.org/protocol/chatstates”)

 if(packetExtension!=null && (ChatState.valueOf(packetExtension.getElementName()) == ChatState.composing ||

ChatState.valueOf(packetExtension.getElementName()) == ChatState.paused ))

{
        // Detected a chatstate notification...
        // return;
     }
 ...

}