use of org.jivesoftware.openfire.muc.cluster.OccupantLeftEvent in project Openfire by igniterealtime.
the class LocalMUCRoom method leaveRoom.
@Override
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");
// 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 {
if (getOccupantsByNickname(leaveRole.getNickname()).size() <= 1) {
// Inform the rest of the room occupants that the user has left the room
broadcastPresence(presence, false);
}
}
} 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();
}
use of org.jivesoftware.openfire.muc.cluster.OccupantLeftEvent in project Openfire by igniterealtime.
the class LocalMUCRoom method kickPresence.
/**
* Kicks the occupant from the room. This means that the occupant will receive an unavailable
* presence with the actor that initiated the kick (if any). The occupant will also be removed
* from the occupants lists.
*
* @param kickPresence the presence of the occupant to kick from the room.
* @param actorJID The JID of the actor that initiated the kick or <tt>null</tt> if the info
* @param nick The actor nickname.
* was not provided.
*/
private void kickPresence(Presence kickPresence, JID actorJID, String nick) {
// Get the role(s) to kick
List<MUCRole> occupants = new ArrayList<>(occupantsByNickname.get(kickPresence.getFrom().getResource().toLowerCase()));
for (MUCRole kickedRole : occupants) {
// Add the actor's JID that kicked this user from the room
if (actorJID != null && actorJID.toString().length() > 0) {
Element frag = kickPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
Element actor = frag.element("item").addElement("actor");
actor.addAttribute("jid", actorJID.toBareJID());
if (nick != null) {
actor.addAttribute("nick", nick);
}
}
// Send the unavailable presence to the banned user
kickedRole.send(kickPresence);
// Remove the occupant from the room's occupants lists
OccupantLeftEvent event = new OccupantLeftEvent(this, kickedRole);
event.setOriginator(true);
event.run();
// Remove the occupant from the room's occupants lists
event = new OccupantLeftEvent(this, kickedRole);
CacheFactory.doClusterTask(event);
}
}
Aggregations