Urgent : Users leaving the room

Dear members,

I am developing a client for Jabber using smack. One of the tasks that I need to undertake is the following:

When a new user joins the room (I use MultiUserChat), I need to display this information on a list/combobox. I have accomplished this using the participantlistener.

My problem now is the reverse - i need to remove an user from the list/combo box whenever he/she leaves. How do I accomplish that?

Basically, to remove an user from the list/combo box, I need to somehow know who is exactly leaving. Then, I could check the entries in the list/combo and delete it off. How do I know who has left the room? What method do I need to use and under which class?

Thanking You,

Vimal Kumar S

Hey Vimal,

Your participantListener will receive available and unavailable presences of room occupants. Both presences will include the room JID of the occupant that just left or joined the room. With that information you should be able to accomplish what you are looking for.

Regards,

– Gato

Dear Mr.Gato,

Your reply was helpful to an extent. However, let me give you the code that I use to check for messages to the room from people in the room:

PacketListener packetListener = new PacketListener() {

public void processPacket(Packet packet) {

try{

Message msg = muc.nextMessage();

String from = packet.getFrom();

}

catch(Exception e){System.out.println(e);}

}

Presence is given to be a directly known subclass of the PacketListener. Now, I need to check for the Presence type of the “from”. How can I do it?

Thanks and regards,

Vimal Kumar

Hey Vimal,

I assume that the listener presented in your code is being added to the MultiUserChat sending the #addMessageListener message. So that listener is invoked when the room receives new messages.

In order to be notified when a new presence (either available or unavailable) is received you need to use #addParticipantListener with a new listener. This new listener will receive the newly received presence. You can then send #getFrom, #getType to the received presence to get the information you need.

Hope that helps.

Regards,

– Gato