From df353199d0f36a421bec176d15153d58d88dc9a9 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Wed, 2 Apr 2003 22:46:40 +0000 Subject: [PATCH] Added ability to add listeners. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1861 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/GroupChat.java | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/source/org/jivesoftware/smack/GroupChat.java b/source/org/jivesoftware/smack/GroupChat.java index da20e04cd..c728ab714 100644 --- a/source/org/jivesoftware/smack/GroupChat.java +++ b/source/org/jivesoftware/smack/GroupChat.java @@ -75,6 +75,8 @@ public class GroupChat { private boolean joined = false; private List participants = new ArrayList(); + private PacketFilter presenceFilter; + private PacketFilter messageFilter; private PacketCollector messageCollector; /** @@ -89,11 +91,11 @@ public class GroupChat { this.connection = connection; this.room = room; // Create a collector for all incoming messages. - PacketFilter messageFilter = new AndFilter(new FromContainsFilter(room), + messageFilter = new AndFilter(new FromContainsFilter(room), new PacketTypeFilter(Message.class)); messageCollector = connection.createPacketCollector(messageFilter); // Create a listener for all presence updates. - PacketFilter presenceFilter = new AndFilter(new FromContainsFilter(room), + presenceFilter = new AndFilter(new FromContainsFilter(room), new PacketTypeFilter(Presence.class)); connection.addPacketListener(new PacketListener() { public void processPacket(Packet packet) { @@ -213,6 +215,18 @@ public class GroupChat { } } + /** + * Adds a packet listener that will be notified of any new Presence packets + * sent to the group chat. Using a listener is a suitable way to know when the list + * of participants should be re-loaded due to any changes. + * + * @param listener a packet listener that will be notified of any presence packets + * sent to the group chat. + */ + public void addParticipantListner(PacketListener listener) { + connection.addPacketListener(listener, presenceFilter); + } + /** * Sends a message to the chat room. * @@ -281,4 +295,14 @@ public class GroupChat { public Message nextMessage(long timeout) { return (Message)messageCollector.nextResult(timeout); } + + /** + * Adds a packet listener that will be notified of any new messages in the + * group chat. + * + * @param listener a packet listener. + */ + public void addMessageListener(PacketListener listener) { + connection.addPacketListener(listener, messageFilter); + } }