public CompletableFuture<Void> sendLeavePresenceToExistingOccupants(MUCOccupant leavingOccupant) {
        // Send the presence of this new occupant to existing occupants
        Log.trace( "Send presence of leaving occupant '{}' to existing occupants of room '{}'.", leavingOccupant.getUserAddress(), this.getJID() );
        try {
            final Presence presence = leavingOccupant.getPresence(); // This returns a copy. Modifications will not be applied to the original.
            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 occupant data is one we should broadcast a leave packet for,
            // or if the leaving occupant is using multi-session nick (in which case _only_ the leaving client should be informed).
            if(!canBroadcastPresence(leavingOccupant.getRole()) || getOccupantsByNickname(leavingOccupant.getNickname()).size() > 1){
                // Inform the leaving user that he/she has left the room
                leavingOccupant.send(createSelfPresenceCopy(presence, false));
                return CompletableFuture.completedFuture(null);
            }
            else {
                // Inform all room occupants that the user has left the room
                if (JOIN_PRESENCE_ENABLE.getValue()) {
                    return broadcastPresence(presence, false, leavingOccupant);
                }
            }
        }
        catch (Exception e) {
            Log.error( "An exception occurred while sending leave presence of occupant '{}' to the other occupants of room: '{}'.", leavingOccupant.getUserAddress(), this.getJID(), e);
        }
        return CompletableFuture.completedFuture(null);
    }
Sends presence of a leaving occupant to applicable occupants of the room that is being left.

@param leavingOccupant the occupant that is leaving.
xmppserver/src/main/java/org/jivesoftware/openfire/muc/MUCRoom.java