mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 16:22:06 +01:00
Allows to filter messages by message type and sender or by thread
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2162 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
7b8c9d1780
commit
a063ecd602
1 changed files with 23 additions and 10 deletions
|
@ -54,8 +54,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.*;
|
||||||
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
|
||||||
|
@ -70,7 +69,14 @@ public class Chat {
|
||||||
* A prefix helps to make sure that ID's are unique across mutliple instances.
|
* A prefix helps to make sure that ID's are unique across mutliple instances.
|
||||||
*/
|
*/
|
||||||
private static String prefix = StringUtils.randomString(5);
|
private static String prefix = StringUtils.randomString(5);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value that indicates the message filter type to use. When true, only the messages with
|
||||||
|
* the Chat's id will be filtered, otherwise the messages of type "chat" and from the Chat´s
|
||||||
|
* participant will be filtered.
|
||||||
|
*/
|
||||||
|
public static boolean FILTER_ONLY_BY_THREAD = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps track of the current increment, which is appended to the prefix to
|
* Keeps track of the current increment, which is appended to the prefix to
|
||||||
* forum a unique ID.
|
* forum a unique ID.
|
||||||
|
@ -100,13 +106,8 @@ public class Chat {
|
||||||
* @param participant the user to chat with.
|
* @param participant the user to chat with.
|
||||||
*/
|
*/
|
||||||
public Chat(XMPPConnection connection, String participant) {
|
public Chat(XMPPConnection connection, String participant) {
|
||||||
this.connection = connection;
|
|
||||||
this.participant = participant;
|
|
||||||
// Automatically assign the next chat ID.
|
// Automatically assign the next chat ID.
|
||||||
chatID = nextID();
|
this(connection, participant, nextID());
|
||||||
|
|
||||||
messageFilter = new ThreadFilter(chatID);
|
|
||||||
messageCollector = connection.createPacketCollector(messageFilter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +122,19 @@ public class Chat {
|
||||||
this.participant = participant;
|
this.participant = participant;
|
||||||
this.chatID = chatID;
|
this.chatID = chatID;
|
||||||
|
|
||||||
messageFilter = new ThreadFilter(chatID);
|
if (FILTER_ONLY_BY_THREAD) {
|
||||||
|
// Filter the messages whose thread equals Chat's id
|
||||||
|
messageFilter = 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));
|
||||||
|
}
|
||||||
messageCollector = connection.createPacketCollector(messageFilter);
|
messageCollector = connection.createPacketCollector(messageFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue