I am trying to implement a MultiUserChat with the smackx api.
So far I managed to create a new MultiUserChat room, join it, and send invites out. My problem as of now is how to find out who is in the chat room if someone joined the chat room or left it. I thought that adding a presence listener to the chat room might do the trick:
muc.addParticipantListener(new PacketListener() {
@Override
public void processPacket(Packet packet) {
System.out.println("user count changed, now:" + muc.getOccupcantsCount());
}
});
The Javadoc for addParticipantListener
states
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 occupants should be re-loaded due to any changes.
So I thought that this would work. However, within the processPacket
method muc.getOccupantsCount()
as well as muc.getOccupants()
both return the values BEFORE the processPacket
call.
So if there is only one user in the chat room and another joins, the output will be
user count changed, now: 1
If there are two users and another joins, the output is
user count changed, now: 2
And if there are three users and one leaves, the output is
user count changed, now: 3
Respectively, muc.getOccupants()
won't give me the user that just joined when called within processPacket
, and still gives me the user that just left.
How can I effectively find out who currently is in the chat room from within processPacket
?