}
public void leaveRoom(MUCRole leaveRole) {
if (leaveRole.isLocal()) {
// Ask other cluster nodes to remove occupant from room
OccupantLeftEvent event = new OccupantLeftEvent(this, leaveRole);
CacheFactory.doClusterTask(event);
}
try {
Presence originalPresence = leaveRole.getPresence();
Presence presence = originalPresence.createCopy();
presence.setType(Presence.Type.unavailable);
presence.setStatus(null);
// Change (or add) presence information about roles and affiliations
Element childElement = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
if (childElement == null) {
childElement = presence.addChildElement("x", "http://jabber.org/protocol/muc#user");
}
Element item = childElement.element("item");
if (item == null) {
item = childElement.addElement("item");
}
item.addAttribute("role", "none");
// Check to see if the user's original presence is one we should broadcast
// a leave packet for. Need to check the original presence because we just
// set the role to "none" above, which is always broadcast.
if(!shouldBroadcastPresence(originalPresence)){
// Inform the leaving user that he/she has left the room
leaveRole.send(presence);
}
else {
// Inform the rest of the room occupants that the user has left the room
broadcastPresence(presence);
}
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
// Remove occupant from room and destroy room if empty and not persistent
OccupantLeftEvent event = new OccupantLeftEvent(this, leaveRole);
event.setOriginator(true);
event.run();
}