Skip to content

Commit

Permalink
feat: allow save messages without body
Browse files Browse the repository at this point in the history
  • Loading branch information
mightymop committed Jan 20, 2022
1 parent 1d255b9 commit 57a1f29
Show file tree
Hide file tree
Showing 9 changed files with 619 additions and 21 deletions.
17 changes: 17 additions & 0 deletions src/i18n/monitoring_i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ archive.settings.logs.link.secure=Log files are also available via an encrypted
archive.settings.logs.public.enable=Public Group Chat Weblog
archive.settings.logs.public.enable.description=Expose log files of public group chats through a web interface.

archive.settings.empty.title=Archive Messages without body
archive.settings.empty.titleMUC=Archive Messages without body in MUC
archive.settings.empty.unknownmessages=Unknown Message
archive.settings.empty.chatmarker=Archive Chatmarkers (XEP-0333)
archive.settings.empty.chatmarker_type_markable=Markable (XEP-0333)
archive.settings.empty.chatmarker_type_received=Received (XEP-0333)
archive.settings.empty.chatmarker_type_displayed=Displayed (XEP-0333)
archive.settings.empty.chatmarker_type_acknowledged=Acknowledged (XEP-0333)
archive.settings.empty.retraction=Retraction (XEP-0424)
archive.settings.empty.chatstate_notification_active=Activ (XEP-0085)
archive.settings.empty.chatstate_notification_inactive=Inactiv (XEP-0085)
archive.settings.empty.chatstate_notification_paused=Paused (XEP-0085)
archive.settings.empty.chatstate_notification_composing=Composing (XEP-0085)
archive.settings.empty.chatstate_notification_gone=Gone (XEP-0085)
archive.settings.empty.message_delivery_receipts_received=Received (XEP-0184)
archive.settings.empty.message_delivery_receipts_request=Request (XEP-0184)

archive.search.title = Search Archive
archive.search.participants = Participant(s):
archive.search.participants.tooltip = Enter or browse for the name of the participant to search for. \
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/monitoringservice_i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ system_property.conversation.roomsArchived=List of MUC rooms in which to archive
system_property.conversation.search.updateInterval=How often, in minutes, to update the search index
system_property.monitoring.search.allow-unrecognized-fields=If 'true', silently ignores unrecognized search filters in queries, which otherwise result in error responses.
system_property.stats.mock.viewer=Displays random stats in Monitoring plugin admin pages
system_property.conversation.emptyMessageArchivingBitmask=Bitmask for saving messages without body (One on One)
system_property.conversation.emptyMessageArchivingBitmaskMUC=Bitmask for saving messages without body (MUC)
35 changes: 33 additions & 2 deletions src/java/org/jivesoftware/openfire/archive/ArchiveInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.jivesoftware.openfire.archive;

import org.jivesoftware.openfire.archive.EmptyMessageUtils.EmptyMessageType;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.interceptor.InterceptorManager;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void interceptPacket(Packet packet, Session session, boolean incoming, bo
// Ignore any messages that don't have a body so that we skip events.
// Note: XHTML messages should always include a body so we should be ok. It's
// possible that we may need special XHTML filtering in the future, however.
if (message.getBody() != null) {
if (message.getBody() != null||this.conversationManager.isEmptyMessageArchivingEnabled()) {
// Only process messages that are between two users, group chat rooms, or gateways.
if (conversationManager.isConversation(message)) {
//take care on blocklist
Expand All @@ -89,11 +90,41 @@ public void interceptPacket(Packet packet, Session session, boolean incoming, bo
JID sender = message.getFrom();
JID receiver = message.getTo();
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver),
if (message.getBody()!=null)
{
eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver),
ConversationEvent.chatMessageReceived(sender, receiver,
conversationManager.isMessageArchivingEnabled() ? message.getBody() : null,
conversationManager.isMessageArchivingEnabled() ? message.toXML() : null,
new Date()));
}
else
{
EmptyMessageType emptyMessageType = EmptyMessageUtils.getMessageType(message.getElement());

long bitmask = conversationManager.getSpeficifEmptyMessageArchivingEnabled();

if (emptyMessageType==EmptyMessageType.TYPE_UNKNOWN && ((bitmask & EmptyMessageType.TYPE_UNKNOWN.getValue())==EmptyMessageType.TYPE_UNKNOWN.getValue())||
(bitmask & EmptyMessageType.TYPE_CHATMARKER_MARKABLE.getValue())==EmptyMessageType.TYPE_CHATMARKER_MARKABLE.getValue()||
(bitmask & EmptyMessageType.TYPE_CHATMARKER_RECEIVED.getValue())==EmptyMessageType.TYPE_CHATMARKER_RECEIVED.getValue()||
(bitmask & EmptyMessageType.TYPE_CHATMARKER_DISPLAYED.getValue())==EmptyMessageType.TYPE_CHATMARKER_DISPLAYED.getValue()||
(bitmask & EmptyMessageType.TYPE_CHATMARKER_ACKNOWLEDGED.getValue())==EmptyMessageType.TYPE_CHATMARKER_ACKNOWLEDGED.getValue()||
(bitmask & EmptyMessageType.TYPE_MESSAGE_RETRACTION.getValue())==EmptyMessageType.TYPE_MESSAGE_RETRACTION.getValue()||
(bitmask & EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_ACTIVE.getValue())==EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_ACTIVE.getValue()||
(bitmask & EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_COMPOSING.getValue())==EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_COMPOSING.getValue()||
(bitmask & EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_PAUSED.getValue())==EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_PAUSED.getValue()||
(bitmask & EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_INACTIVE.getValue())==EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_INACTIVE.getValue()||
(bitmask & EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_GONE.getValue())==EmptyMessageType.TYPE_CHATSTATE_NOTIFICATION_GONE.getValue()||
(bitmask & EmptyMessageType.TYPE_MESSAGE_DELIVERY_RECEIPTS_RECEIVED.getValue())==EmptyMessageType.TYPE_MESSAGE_DELIVERY_RECEIPTS_RECEIVED.getValue()||
(bitmask & EmptyMessageType.TYPE_MESSAGE_DELIVERY_RECEIPTS_REQUEST.getValue())==EmptyMessageType.TYPE_MESSAGE_DELIVERY_RECEIPTS_REQUEST.getValue())
{
eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver),
ConversationEvent.getEmptyMessageReceivedEvent(sender, receiver,
emptyMessageType,
conversationManager.isMessageArchivingEnabled() ? message.toXML() : null,
new Date()));
}
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/java/org/jivesoftware/openfire/archive/ConversationEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class ConversationEvent {

private String nickname;

private EmptyMessageUtils.EmptyMessageType emptyMessageType;

/**
* Do not use this constructor. It only exists for serialization purposes.
*/
Expand Down Expand Up @@ -195,4 +197,14 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(type, date, body, stanza, sender, receiver, roomJID, user, nickname);
}

public static ConversationEvent getEmptyMessageReceivedEvent(JID sender, JID receiver, EmptyMessageUtils.EmptyMessageType emptyMessageType, String stanza, Date date) {
ConversationEvent event = new ConversationEvent();
event.type = Type.chatMessageReceived;
event.sender = sender;
event.receiver = receiver;
event.emptyMessageType = emptyMessageType;
event.date = date;
return event;
}
}
Loading

0 comments on commit 57a1f29

Please sign in to comment.