Setting message properties

I’‘m having some problems figuring out where to set a message property. I have added a check box to the standard chat window and I want to set a message property based on whether or not it’'s checked. Which class would I use to do this?

Not sure what your context is, but I encountered this guide on setting message properties and thought it might help. ml

Thanks for the reply. I’‘m familiar with the setProperty() and getProperty() methods. My problem is that I can’'t figure out from what context to access the message object. There are a couple of Listener classes that seemed like good possibilities (ChatRoomListener, MessageListener, etc.), but none of them have access to both the message object that is generated by the chat room and the control (in this case a checkbox) that is in the chat room window. Any other ideas?

As of what sipsters post was sorta about in another post elsewhere:

maybe you could use a PacketListener from the smack api and just cast it to a Message object.

Something similar to this:


public class MyMessageListener implements PacketListener {     public void processPacket(Packet packet) {         Message message = (Message) packet;         String from = message.getFrom();
        ChatRoom chatRoom = SparkManager.getChatManager().getChatRoom(from);
        // Do the things you needed to here with the ChatRoom instance for that user.


There is probably more that you are looking for then just this.

If there is more detail you can give, I’'ll try my best to help.


Message was edited by: cyclone

I think that’‘s exaclty what I was looking for. I guess I didn’‘t realize that the packet object was the message itself. I’‘m assuming there’'s an “addPacketListener()” method somewhere to add this new listener to Spark?

Sure is… it is with the XMPPConnection object.

Which you used to initiate the connection.


Thanks, I’'m getting closer.

When does the processPacket() method get called? I need to process the message in two places. Once, just before it is sent, to determine whether or not to set the property (based on the state of the checkbox in the chat room). And again, when the other end receives the message, to see if the property is set and then do something with the message based on that.

The processPacket() is called whenever a packet comes in.


For outgoing messages, you’'ll want a different listener:

You will want to implement the PacketInterceptor interface PacketInterceptor.html

The XMPPConnection also has an addPacketWriterInterceptor(PacketInterceptor, PacketFilter)


Message was edited by: cyclone

Thank you very much. I think that fills in the missing piece.