From c2a215eacc73e3f196732f7708767a860399a7c3 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Wed, 2 Apr 2003 22:52:07 +0000 Subject: [PATCH] Added ability to add listeners for messages. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1862 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/Chat.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/source/org/jivesoftware/smack/Chat.java b/source/org/jivesoftware/smack/Chat.java index 92f5b70cb..6aab00689 100644 --- a/source/org/jivesoftware/smack/Chat.java +++ b/source/org/jivesoftware/smack/Chat.java @@ -55,6 +55,7 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.filter.ThreadFilter; +import org.jivesoftware.smack.filter.PacketFilter; /** * A chat is a series of messages sent between two users. Each chat has @@ -89,6 +90,7 @@ public class Chat { private XMPPConnection connection; private String chatID; private String participant; + private PacketFilter messageFilter; private PacketCollector messageCollector; /** @@ -103,7 +105,8 @@ public class Chat { // Automatically assign the next chat ID. chatID = nextID(); - messageCollector = connection.createPacketCollector(new ThreadFilter(chatID)); + messageFilter = new ThreadFilter(chatID); + messageCollector = connection.createPacketCollector(messageFilter); } /** @@ -225,4 +228,14 @@ public class Chat { public Message nextMessage(long timeout) { return (Message)messageCollector.nextResult(timeout); } -} + + /** + * 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); + } +} \ No newline at end of file