1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-29 09:42:06 +01:00

Added ability to add listeners for messages.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1862 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-04-02 22:52:07 +00:00 committed by mtucker
parent df353199d0
commit c2a215eacc

View file

@ -55,6 +55,7 @@ package org.jivesoftware.smack;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.filter.ThreadFilter; 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 * 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 XMPPConnection connection;
private String chatID; private String chatID;
private String participant; private String participant;
private PacketFilter messageFilter;
private PacketCollector messageCollector; private PacketCollector messageCollector;
/** /**
@ -103,7 +105,8 @@ public class Chat {
// Automatically assign the next chat ID. // Automatically assign the next chat ID.
chatID = nextID(); 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) { public Message nextMessage(long timeout) {
return (Message)messageCollector.nextResult(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);
}
} }