Hi,
I am facing a new challenge in my XMPP quest! Indeed, I am trying to filter Chat’‘s packets from contacts listed in a Black List (group of the user’'s roster). To comply with my Interface structure, filters must be added to XMPPConnection. As a matter of fact, I created a method that executes nearly that:
- public void filterBlackList() {
XMPPConnection connection = (XMPPConnection)sessionInfos.getConnection();
//Packet Filter definition (blocks black list contacts)
Iterator iti = null;
RosterEntry ent;
AndFilter opposedFilter = new AndFilter();
RosterGroup group = contactList.getGroup(“BlackList”); // contactList is the user’'s Roster
if(group != null) {
iti = group.getEntries();
}
if(iti != null) {
AndFilter contactFilter = new AndFilter();
while(iti.hasNext()) {
contactFilter = new AndFilter(new MessageTypeFilter(Message.Type.CHAT),
new FromContainsFilter(((RosterEntry)iti.next()).getUser()));
opposedFilter.addFilter(contactFilter);
}
}
opposedFilter.addFilter(new MessageTypeFilter(Message.Type.GROUP_CHAT));
//adds Listener and PacketFilter to connection
connection.removePacketListener(pl); //pl is a PacketFilter
connection.addPacketListener(pl,new NotFilter(opposedFilter));
}+
I call this method when user logins and each times user adds or removes entry from BlackList group. I thought this could works but it seems that it do not… In fact, I cannot understand why but packet are not filtered or all packets are refused, and sometimes I get an error on PacketListener#processPacket() method that I did not have before.
So, is there anything I coded badly? Or is there a cooler way to sort out this “black list” use case problem?
Thanks,
Seb