Hello,
I looked for an answer to this problem I encountered but couldn’t find one. If you can help me with his here or direct me to a solution in some other discussion I would appreciate it.
I wanted to add MUC support to my android application using the asmack library. However, when I tried to add my custom class, implementing PacketListener, as both the MessageListener and ParticipantLisener in the MultiUserChat class this didn’t work as only the last listener worked.
I looked into the MultiUserChat.java code and found where the problem was:
messageFilter =
new AndFilter(
new FromMatchesFilter(room),
new MessageTypeFilter(Message.Type.groupchat));
messageFilter = new AndFilter(messageFilter, new PacketFilter() {
public boolean accept(Packet packet) {
Message msg = (Message) packet;
return msg.getBody() != null;
}
});
public void addMessageListener(PacketListener listener) {
connection.addPacketListener(listener, messageFilter);
connectionListeners.add(listener);
}
presenceFilter =
new AndFilter(new FromMatchesFilter(room), new PacketTypeFilter(Presence.class));
public void addParticipantListener(PacketListener listener) {
connection.addPacketListener(listener, presenceFilter);
connectionListeners.add(listener);
}
First of all, the messageFilter object is created once so the first creation is useless. Then, the listener problem. The listener is added both to the local list connectionListeners and to the main connection PacketListener list. However, the former is never used in the MUC class so I guess that the packets are only forwarded thanks to the main connection PacketListener list to my custom class. The problem is that the packetFilter for this listener is overwritten if I’m using only one class in both cases. A solution is to use two different classes - one for MessageListener and another one for ParticipantListener but I would like to avoid it and do it all in a single class. The current implementation doesn’t allow me to do that.