public void addMessage(@Nonnull final Message... packets)
    {
        // Room subject change messages are special
        for (final Message packet : packets) {
            boolean subjectChange = isSubjectChangeRequest(packet);
            if (subjectChange) {
                roomSubject = packet;
            }
        }

        // Do not process subject changes anymore after this point.
        final List<Message> messages = Arrays.stream(packets).filter(p -> !isSubjectChangeRequest(p)).collect(Collectors.toList());

        if (messages.isEmpty()) {
            return;
        }

        // get the conditions based on default or not
        final Type strategyType;
        final int strategyMaxNumber;
        if (type == Type.defaulType && parent != null) {
            strategyType = parent.getType();
            strategyMaxNumber = parent.getMaxNumber();
        }
        else {
            strategyType = type;
            strategyMaxNumber = maxNumber;
        }

        final Lock lock = MUC_HISTORY_CACHE.getLock(roomJID);
        lock.lock();
        try {
            final CacheableOptional<Messages> optional = MUC_HISTORY_CACHE.get(roomJID);
            final Messages history;
            if (optional == null || optional.isAbsent()) {
                history = new Messages();
            } else {
                history = optional.get();
            }
            for (final Message message : messages) {
                history.add(message, strategyType, strategyMaxNumber);
            }

            // Explicitly add back to cache (Hazelcast won't update-by-reference).
            MUC_HISTORY_CACHE.put(roomJID, CacheableOptional.of(history));
        } finally {
            lock.unlock();
        }
    }
Add a message(s) to the current chat history. The strategy type will determine what
actually happens to the message.

@param packets The messages to add to the chatroom's history.
xmppserver/src/main/java/org/jivesoftware/openfire/muc/HistoryStrategy.java