diff --git a/src/java/org/jivesoftware/openfire/archive/ArchiveInterceptor.java b/src/java/org/jivesoftware/openfire/archive/ArchiveInterceptor.java index 0e49fcf71..8611365b3 100644 --- a/src/java/org/jivesoftware/openfire/archive/ArchiveInterceptor.java +++ b/src/java/org/jivesoftware/openfire/archive/ArchiveInterceptor.java @@ -89,7 +89,7 @@ public void interceptPacket(Packet packet, Session session, boolean incoming, bo JID sender = message.getFrom(); JID receiver = message.getTo(); ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue(); - if (message.getBody()!=null) + if (message.getBody() != null && !message.getBody().isEmpty()) { eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver), ConversationEvent.chatMessageReceived(sender, receiver, @@ -97,20 +97,12 @@ public void interceptPacket(Packet packet, Session session, boolean incoming, bo conversationManager.isMessageArchivingEnabled() ? message.toXML() : null, new Date())); } - else + else if (conversationManager.isEmptyMessageArchivingEnabledFor(message)) { - EmptyMessageType emptyMessageType = EmptyMessageType.getMessageType(message.getElement()); - - long bitmask = conversationManager.getSpecificEmptyMessageArchivingEnabled(); - - if (emptyMessageType!=EmptyMessageType.IGNORE && (bitmask & emptyMessageType.getValue()) == emptyMessageType.getValue()) - { - eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver), - ConversationEvent.getEmptyMessageReceivedEvent(sender, receiver, - emptyMessageType, - conversationManager.isMessageArchivingEnabled() ? message.toXML() : null, - new Date())); - } + eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver), + ConversationEvent.getEmptyMessageReceivedEvent(sender, receiver, + message.toXML(), + new Date())); } } } diff --git a/src/java/org/jivesoftware/openfire/archive/ConversationEvent.java b/src/java/org/jivesoftware/openfire/archive/ConversationEvent.java index 016f51efb..509ac53ae 100644 --- a/src/java/org/jivesoftware/openfire/archive/ConversationEvent.java +++ b/src/java/org/jivesoftware/openfire/archive/ConversationEvent.java @@ -60,8 +60,6 @@ public class ConversationEvent { private String nickname; - private EmptyMessageType emptyMessageType; - /** * Do not use this constructor. It only exists for serialization purposes. */ @@ -198,12 +196,11 @@ public int hashCode() { return Objects.hash(type, date, body, stanza, sender, receiver, roomJID, user, nickname); } - public static ConversationEvent getEmptyMessageReceivedEvent(JID sender, JID receiver, EmptyMessageType emptyMessageType, String stanza, Date date) { + public static ConversationEvent getEmptyMessageReceivedEvent(JID sender, JID receiver, String stanza, Date date) { ConversationEvent event = new ConversationEvent(); event.type = Type.chatMessageReceived; event.sender = sender; event.receiver = receiver; - event.emptyMessageType = emptyMessageType; event.date = date; event.stanza=stanza; return event; diff --git a/src/java/org/jivesoftware/openfire/archive/ConversationManager.java b/src/java/org/jivesoftware/openfire/archive/ConversationManager.java index 06919e694..e80ae83a1 100644 --- a/src/java/org/jivesoftware/openfire/archive/ConversationManager.java +++ b/src/java/org/jivesoftware/openfire/archive/ConversationManager.java @@ -462,6 +462,54 @@ public boolean isMessageArchivingEnabled() { return messageArchivingEnabled; } + /** + * Checks if with the current configuration, message archiving should be enabled for the provided message stanza, + * assuming that it has no body. It does so by evaluating child elements of the stanza for occurrence of elements + * identified in {@link EmptyMessageType}. + * + * This method does not verify if the stanza indeed has no body. + * + * @param message the stanza to evaluate + * @return true if the stanza is eligible for archiving, otherwise false. + */ + public boolean isEmptyMessageArchivingEnabledFor(final Message message) + { + if (!isEmptyMessageArchivingEnabled()) { + return false; + } + + final EmptyMessageType emptyMessageType = EmptyMessageType.getMessageType(message.getElement()); + if (emptyMessageType!=EmptyMessageType.IGNORE) { + return false; + } + final long bitmask = getSpecificEmptyMessageArchivingEnabled(); + return (bitmask & emptyMessageType.getValue()) == emptyMessageType.getValue(); + } + + /** + * Checks if with the current configuration, message archiving should be enabled for the provided message stanza, + * assuming that it has no body. It does so by evaluating child elements of the stanza for occurrence of elements + * identified in {@link EmptyMessageType}. + * + * This method does not verify if the stanza indeed has no body. + * + * @param message the stanza to evaluate + * @return true if the stanza is eligible for archiving, otherwise false. + */ + public boolean isEmptyMessageArchivingEnabledFor(final String message) + { + if (!isEmptyMessageArchivingEnabled()) { + return false; + } + + final EmptyMessageType emptyMessageType = EmptyMessageType.getMessageType(message); + if (emptyMessageType!=EmptyMessageType.IGNORE) { + return false; + } + final long bitmask = getSpecificEmptyMessageArchivingEnabled(); + return (bitmask & emptyMessageType.getValue()) == emptyMessageType.getValue(); + } + /** * Sets whether message archiving is enabled. When enabled, all messages in conversations are stored in the database. Note: it's not possible for * meta-data archiving to be disabled when message archiving is enabled; enabling message archiving automatically enables meta-data archiving. @@ -864,20 +912,9 @@ else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime.t conversationArchiver.archive(conversation); } if (messageArchivingEnabled) { - if (body != null) { + if ((body != null && !body.isEmpty()) || isEmptyMessageArchivingEnabledFor(stanza)) { messageArchiver.archive(new ArchivedMessage(conversation.getConversationID(), sender, receiver, date, body, stanza, false, null) ); } - else - if (isEmptyMessageArchivingEnabled()) { - EmptyMessageType emptyMessageType = EmptyMessageType.getMessageType(stanza); - - long bitmask = getSpecificEmptyMessageArchivingEnabled(); - - if (emptyMessageType!=EmptyMessageType.IGNORE && (bitmask & emptyMessageType.getValue()) == emptyMessageType.getValue()) - { - messageArchiver.archive(new ArchivedMessage(conversation.getConversationID(), sender, receiver, date, body, stanza, false, null) ); - } - } } // Notify listeners of the conversation update. for (ConversationListener listener : conversationListeners) { diff --git a/src/java/org/jivesoftware/openfire/archive/GroupConversationInterceptor.java b/src/java/org/jivesoftware/openfire/archive/GroupConversationInterceptor.java index 686b636b4..a8fb4d4be 100644 --- a/src/java/org/jivesoftware/openfire/archive/GroupConversationInterceptor.java +++ b/src/java/org/jivesoftware/openfire/archive/GroupConversationInterceptor.java @@ -154,20 +154,12 @@ public void messageReceived(JID roomJID, JID user, String nickname, Message mess eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID), ConversationEvent.roomMessageReceived(roomJID, user, null, nickname, withBody ? message.getBody() : null, message.toXML(), now)); } - else + else if (conversationManager.isEmptyMessageArchivingEnabledFor(message)) { - EmptyMessageType emptyMessageType = EmptyMessageType.getMessageType(message.getElement()); - - long bitmask = conversationManager.getSpecificEmptyMessageArchivingForMUCEnabled(); - - if (emptyMessageType!=EmptyMessageType.IGNORE && (bitmask & emptyMessageType.getValue()) == emptyMessageType.getValue()) - { - ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue(); + ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue(); - eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID), - ConversationEvent.getEmptyMessageReceivedEvent(roomJID, user, emptyMessageType, - conversationManager.isMessageArchivingEnabled() ? message.toXML() : null, new Date())); - } + eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID), + ConversationEvent.getEmptyMessageReceivedEvent(roomJID, user, message.toXML(), new Date())); } } }