public CompletableFuture<Void> clearChatHistory() {
        return CompletableFuture.runAsync(() -> {
            if(BULK_MSG_RETRACTION_ENABLED.getValue()) {
                ListIterator<Message> reverseMessageHistory = roomHistory.getReverseMessageHistory();
                while (reverseMessageHistory.hasPrevious()) {
                    Message originalMsg = reverseMessageHistory.previous();
                    Message retractionMsg = new Message();

                    // Sets a unique ID for the retraction message by prefixing the original message ID with "retract-"
                    retractionMsg.setID("retract-" + originalMsg.getID());
                    // Sets the sender of the retraction message to be the chat room itself
                    retractionMsg.setFrom(selfOccupantData.getOccupantJID());
                    // Sets the recipient of the retraction message to be the chat room itself to send to all occupants
                    retractionMsg.setTo(new JID(getName(), getMUCService().getServiceDomain(), null).toBareJID());
                    retractionMsg.setType(Message.Type.groupchat);
                    // An XML element is added to the message to indicate that it is a retraction, with an attribute specifying
                    // the ID of the message being retracted
                    retractionMsg.addChildElement("retract", "urn:xmpp:message-retract:1").addAttribute(
                        "id",
                        new JID(getName(), getMUCService().getServiceDomain(), null).toBareJID()
                    );
                    // A fallback element is added to provide a fallback message for clients that do not support message retraction
                    retractionMsg.addChildElement("fallback", "urn:xmpp:fallback:0").addAttribute(
                        "for",
                        "urn:xmpp:message-retract:1"
                    );
                    retractionMsg.setBody(LocaleUtils.getLocalizedString("muc.room.clear_chat.retraction_fallback_msg"));
                    // Finally, a hint is added to the message to indicate that it should be stored by the client.
                    // This ensures that the retraction event is recorded and can be referenced later.
                    retractionMsg.addChildElement("store", "urn:xmpp:hints");

                    // Broadcast the retraction message but don't store it in the history
                    broadcast(retractionMsg, false);
                }
            }

            // Clear the history of the room from the DB if the room was persistent
            MUCPersistenceManager.clearRoomChatFromDB(this);
            // Remove the history of the room from memory (preventing it to pop up in a new room by the same name).
            roomHistory.purge();
            // Fire event to clear chat room history
            MUCEventDispatcher.roomClearChatHistory(getID(), getJID());
        });
    }
Asynchronously remove the chat history of a room from run-time memory and database storage.
If bulk message retraction is enabled, it sends message retraction stanzas to all occupants.
xmppserver/src/main/java/org/jivesoftware/openfire/muc/MUCRoom.java