I was having problems with Chat class. I traced it to
/**
- Creates a new chat with the specified user.
-
@param connection the connection the chat will use.
-
@param participant the user to chat with.
*/
public Chat(XMPPConnection connection, String participant) {
this.connection = connection;
this.participant = participant;
// Automatically assign the next chat ID.
chatID = nextID();
messageFilter = new ThreadFilter(chatID);
messageCollector = connection.createPacketCollector(messageFilter);
}
/**
- Creates a new chat with the specified user and chat ID (the XMPP "thread).
-
@param connection the connection the chat will use.
-
@param participant the user to chat with.
-
@param chatID the chat ID to use.
*/
public Chat(XMPPConnection connection, String participant, String chatID) {
this.connection = connection;
this.participant = participant;
this.chatID = chatID;
messageCollector = connection.createPacketCollector(new ThreadFilter(chatID));
}
I was using the second version of the constructor. It does not set messageFilter and so I was getting back all types of packets on my call back (because messsageFilter is null) in addMessageListener.
/**
-
Adds a packet listener that will be notified of any new messages in the
-
chat.
- @param listener a packet listener.
*/
public void addMessageListener(PacketListener listener) {
connection.addPacketListener(listener, messageFilter);
}
When I changed the second constructor to set messageFilter like the first, I obtained the behavior I expected. But I don’'t claim to know if that is the intended behavior. Please Advise.
Thanks
MDA