how to differentiate received messages between use

2019-06-28 00:54发布

问题:

I am using servlets to send & receive chat messages to facebook using smack . In that user's "A" & "B" are chating with user "C". If user "C" send's message only to "A" ,that message also received by "B". How to differenciate the messages between users?

finally my problem is ,to whom the message is cmg from facebook.

By using below code to get messages:

public void processMessage(Chat chat, Message message) {

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

                    System.out.println(chat.getParticipant() +"--"+ message.getBody());

                  }
            }

回答1:

Each Message object will contain a header and body. Header is basically a mapping of name value pairs. I would suggest to put userid in header of message. Now in you chat client you can implement message filtering based user id in header. This should resolve your issue.

Edit:

This link : http://www.quepublishing.com/articles/article.aspx?p=26270&seqNum=6 has details on usage of header.