How to prevent a message from being delivered?


I’m trying to prevent certain messages from being delivered to a recipient. I’ve tried to do this with a custom PacketFilter by returning false in PacketFilter.accept(), as well as trying to call packet.setError() and packet.setTo(“none”) inside a custom PacketListener. Log output proves my packet listener/filter are being called and even the message being altered. But no matter what I do, the message is still delivered to the recipient.

I need to make it so that if a message containing certain words is sent to a recipient, then…

  1. the recipient will never receive the message or any indication that a message was sent.

  2. the sender won’t receive any indication that the message wasn’t sent.

  3. the message should basically be blackholed as if it has never existed.

Can anyone please help me?


First of all, this would be better if it was located in the server so it would actually not deliver the offending messages to the client at all. This seems to be what you actually want to accomplish.

That being said.

What type of messages are you trying to vanquish?

PacketFilters are used to match criteria, so they don’t delete messages. They are simply used to direct messages to listeners, for example, so only the appropriate messages will reach a given listener.

Once a message has reached the client, you can choose to not process it. If you are talking about a chat message for instance, you can simply do this in your MessageListener for the specific chat by choosing to not display it.

I need it to be on the client-side, not the server-side.

So how would I use MessageListener to not display the message? MessageListener.processMessage should do what to the message object?

The message listener is what is called when a message is received (there can be multiple), so whatever you choose to do with the message would be done from this listener.

I assume that this is your own custom client, so this listener is where you would direct messages to a UI, for instance. It is also where you can do your content filtering and simply do nothing (drop the message) if the filtering fails.