mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 22:32:06 +01:00
Added ability to add listeners.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1861 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
09935d03b7
commit
df353199d0
1 changed files with 26 additions and 2 deletions
|
@ -75,6 +75,8 @@ public class GroupChat {
|
||||||
private boolean joined = false;
|
private boolean joined = false;
|
||||||
private List participants = new ArrayList();
|
private List participants = new ArrayList();
|
||||||
|
|
||||||
|
private PacketFilter presenceFilter;
|
||||||
|
private PacketFilter messageFilter;
|
||||||
private PacketCollector messageCollector;
|
private PacketCollector messageCollector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,11 +91,11 @@ public class GroupChat {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.room = room;
|
this.room = room;
|
||||||
// Create a collector for all incoming messages.
|
// Create a collector for all incoming messages.
|
||||||
PacketFilter messageFilter = new AndFilter(new FromContainsFilter(room),
|
messageFilter = new AndFilter(new FromContainsFilter(room),
|
||||||
new PacketTypeFilter(Message.class));
|
new PacketTypeFilter(Message.class));
|
||||||
messageCollector = connection.createPacketCollector(messageFilter);
|
messageCollector = connection.createPacketCollector(messageFilter);
|
||||||
// Create a listener for all presence updates.
|
// Create a listener for all presence updates.
|
||||||
PacketFilter presenceFilter = new AndFilter(new FromContainsFilter(room),
|
presenceFilter = new AndFilter(new FromContainsFilter(room),
|
||||||
new PacketTypeFilter(Presence.class));
|
new PacketTypeFilter(Presence.class));
|
||||||
connection.addPacketListener(new PacketListener() {
|
connection.addPacketListener(new PacketListener() {
|
||||||
public void processPacket(Packet packet) {
|
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.
|
* Sends a message to the chat room.
|
||||||
*
|
*
|
||||||
|
@ -281,4 +295,14 @@ public class GroupChat {
|
||||||
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
|
||||||
|
* group chat.
|
||||||
|
*
|
||||||
|
* @param listener a packet listener.
|
||||||
|
*/
|
||||||
|
public void addMessageListener(PacketListener listener) {
|
||||||
|
connection.addPacketListener(listener, messageFilter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue