powered by Jive Software

Message writer listener for chat

/**

  • 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;

if (FILTER_ONLY_BY_THREAD) {

// Filter the messages whose thread equals Chat’'s id

messageFilter = new ThreadFilter(chatID);

messageWriterFilter = new ThreadFilter(chatID);

}

else {

// Filter the messages of type “chat” and sender equals Chat’'s participant

messageFilter =

new OrFilter(

new AndFilter(

new MessageTypeFilter(Message.Type.CHAT),

new FromContainsFilter(participant)),

new ThreadFilter(chatID));

messageWriterFilter = new OrFilter(

new AndFilter (

new MessageTypeFilter(Message.Type.CHAT),

new ToContainsFilter(participant)),

new ThreadFilter(chatID));

}

messageCollector = connection.createPacketCollector(messageFilter);

}

/**

  • Adds a packet writer listener that will be notified of out-bound messages

  • in the chat

  • @param listener

*/

public void addMessageWriterListener(PacketListener listener){

connection.addPacketWriterListener(listener, messageWriterFilter);

}