private void sendRoomHistoryAfterJoin(@Nonnull final JID realAddress, @Nonnull MUCOccupant joiningOccupant, @Nullable HistoryRequest historyRequest )
    {
        if (historyRequest == null) {
            Log.trace( "Sending default room history to user '{}' that joined room '{}'.", realAddress, this.getJID() );
            final Iterator<Message> history = roomHistory.getMessageHistory();
            while (history.hasNext()) {
                // OF-2163: Prevent modifying the original history stanza (that can be retrieved by others later) by making a defensive copy.
                //          This prevents the stanzas in the room history to have a 'to' address for the last user that it was sent to.
                final Message message = history.next().createCopy();
                joiningOccupant.send(message);
            }
        } else {
            Log.trace( "Sending user-requested room history to user '{}' that joined room '{}'.", realAddress, this.getJID() );
            historyRequest.sendHistory(joiningOccupant, roomHistory);
        }
    }
Sends the room history to a user that just joined the room.
xmppserver/src/main/java/org/jivesoftware/openfire/muc/MUCRoom.java