Skip to content

Commit

Permalink
xep333 rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
mightymop committed Feb 17, 2021
1 parent 8a0edc1 commit 50bc9f2
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/i18n/monitoring_i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ archive.settings.cancel = Cancel
archive.settings.rebuild = Rebuild Index
archive.settings.any = Any
archive.settings.one_to_one=Archive one-to-one chats
archive.settings.chatmarker=Archive chatmarkers (XEP-0333)
archive.settings.group_chats=Archive group chats
archive.settings.group_chats.stanzas=Archive stanzas for group chats
archive.settings.certain_rooms=Only archive conversations of the following room names (separated by comma)
Expand Down
22 changes: 20 additions & 2 deletions src/java/org/jivesoftware/openfire/archive/ArchiveInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
Expand Down Expand Up @@ -63,7 +64,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||(message.getBody()==null&&JiveGlobals.getBooleanProperty("conversation.chatmarkerArchiving", false))) {
// Only process messages that are between two users, group chat rooms, or gateways.
if (conversationManager.isConversation(message)) {
// Process this event in the senior cluster member or local JVM when not in a cluster
Expand All @@ -74,11 +75,28 @@ 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
{
String stanza = message.toXML();
ChatMarker.TYPE markertype = ChatMarker.searchForXep0333(stanza);

if (markertype!=ChatMarker.TYPE.NONE)
{
eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver),
ConversationEvent.chatmarkerMessageReceived(sender, receiver,markertype,
conversationManager.isMessageArchivingEnabled() ? message.toXML() : null,
new Date()));
}
}
}
}
}
Expand Down
68 changes: 68 additions & 0 deletions src/java/org/jivesoftware/openfire/archive/ChatMarker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.jivesoftware.openfire.archive;

public class ChatMarker {

public enum TYPE
{
NONE,
MARKABLE,
RECEIVED,
DISPLAYED,
ACKNOWLEGED;
}

public static TYPE searchForXep0333(String stanza)
{
if (stanza==null)
{
return TYPE.NONE;
}

int idxmarkable = stanza.indexOf("<markable");
int idxreceived= stanza.indexOf("<received");
int idxdisplayed = stanza.indexOf("<displayed");
int idxacknowled = stanza.indexOf("<acknowledged");

if (idxmarkable!=-1)
{
int idxEnd = stanza.indexOf("/>",idxmarkable);
if (idxEnd==-1)
{
idxEnd = stanza.indexOf("</markable>",idxmarkable);
}
return idxEnd!=-1?(stanza.substring(idxmarkable, idxEnd).contains("urn:xmpp:chat-markers:0")?TYPE.MARKABLE:TYPE.NONE):TYPE.NONE;
}
else
if (idxreceived!=-1)
{
int idxEnd = stanza.indexOf("/>",idxreceived);
if (idxEnd==-1)
{
idxEnd = stanza.indexOf("</received>",idxmarkable);
}
return idxEnd!=-1?(stanza.substring(idxreceived, idxEnd).contains("urn:xmpp:chat-markers:0")?TYPE.RECEIVED:TYPE.NONE):TYPE.NONE;
}
else
if (idxdisplayed!=-1)
{
int idxEnd = stanza.indexOf("/>",idxdisplayed);
if (idxEnd==-1)
{
idxEnd = stanza.indexOf("</displayed>",idxmarkable);
}
return idxEnd!=-1?(stanza.substring(idxdisplayed, idxEnd).contains("urn:xmpp:chat-markers:0")?TYPE.DISPLAYED:TYPE.NONE):TYPE.NONE;
}
else
if (idxacknowled!=-1)
{
int idxEnd = stanza.indexOf("/>",idxacknowled);
if (idxEnd==-1)
{
idxEnd = stanza.indexOf("</acknowledged>",idxmarkable);
}
return idxEnd!=-1?(stanza.substring(idxacknowled, idxEnd).contains("urn:xmpp:chat-markers:0")?TYPE.ACKNOWLEGED:TYPE.NONE):TYPE.NONE;
}
else
return TYPE.NONE;
}
}
11 changes: 11 additions & 0 deletions src/java/org/jivesoftware/openfire/archive/ConversationEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ConversationEvent implements Externalizable {
private Date date;
private String body;
private String stanza;
private ChatMarker.TYPE marker;

private JID sender;
private JID receiver;
Expand Down Expand Up @@ -147,6 +148,16 @@ public static ConversationEvent chatMessageReceived(JID sender, JID receiver, St
event.sender = sender;
event.receiver = receiver;
event.body = body;
event.date = date;
return event;
}

public static ConversationEvent chatmarkerMessageReceived(JID sender, JID receiver, ChatMarker.TYPE marker, String stanza, Date date) {
ConversationEvent event = new ConversationEvent();
event.type = Type.chatMessageReceived;
event.sender = sender;
event.receiver = receiver;
event.marker = marker;
event.stanza = stanza;
event.date = date;
return event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public class ConversationManager implements ComponentEventListener{
*/
private boolean roomArchivingEnabled;
private boolean roomArchivingStanzasEnabled;

private boolean chatmarkerArchivingEnabled;

/**
* List of room names to archive. When list is empty then all rooms are archived (if roomArchivingEnabled is enabled).
*/
Expand Down Expand Up @@ -143,6 +146,9 @@ public void start() {
Log.warn("Metadata archiving must be enabled when message archiving is enabled. Overriding setting.");
metadataArchivingEnabled = true;
}

chatmarkerArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.chatmarkerArchiving", false);

roomArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchiving", false);
roomArchivingStanzasEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchivingStanzas", false);
roomsArchived = StringUtils.stringToCollection(JiveGlobals.getProperty("conversation.roomsArchived", ""));
Expand Down Expand Up @@ -269,6 +275,15 @@ public boolean isPartialSample() {
InternalComponentManager.getInstance().addListener(this);
}

public boolean isChatmarkerArchivingEnabled() {
return chatmarkerArchivingEnabled;
}

public void setChatmarkerArchivingEnabled(boolean chatmarkerArchivingEnabled) {
this.chatmarkerArchivingEnabled = chatmarkerArchivingEnabled;
JiveGlobals.setProperty("conversation.chatmarkerArchiving", Boolean.toString(chatmarkerArchivingEnabled));
}

public void stop() {
cleanupTask.cancel();
cleanupTask = null;
Expand Down Expand Up @@ -643,6 +658,9 @@ public void removeConversationListener(ConversationListener listener) {
void processMessage(JID sender, JID receiver, String body, String stanza, Date date) {
Log.trace("Processing message from date {}...", date );
String conversationKey = getConversationKey(sender, receiver);

ChatMarker.TYPE chatmarker=ChatMarker.searchForXep0333(stanza);

synchronized (conversationKey.intern()) {
Conversation conversation = conversations.get(conversationKey);
// Create a new conversation if necessary.
Expand Down Expand Up @@ -693,7 +711,7 @@ else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime)
conversationArchiver.archive(conversation);
}
if (messageArchivingEnabled) {
if (body != null) {
if (body != null||(body==null&&chatmarkerArchivingEnabled&&chatmarker!=ChatMarker.TYPE.NONE)) {
/* OF-677 - Workaround to prevent null messages being archived */
messageArchiver.archive(new ArchivedMessage(conversation.getConversationID(), sender, receiver, date, body, stanza, false, null) );
}
Expand Down Expand Up @@ -725,6 +743,9 @@ else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime)
void processRoomMessage(JID roomJID, JID sender, JID receiverIfPM, String nickname, String body, String stanza, Date date) {
Log.trace("Processing room {} message from date {}.", roomJID, date );
String conversationKey = getRoomConversationKey(roomJID);

ChatMarker.TYPE chatmarker=ChatMarker.searchForXep0333(stanza);

synchronized (conversationKey.intern()) {
Conversation conversation = conversations.get(conversationKey);
// Create a new conversation if necessary.
Expand Down Expand Up @@ -759,7 +780,7 @@ else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime)
}
if (roomArchivingEnabled && (roomsArchived.isEmpty() || roomsArchived.contains(roomJID.getNode()))) {
JID jid = new JID(roomJID + "/" + nickname);
if (body != null) {
if (body != null||(body==null&&chatmarkerArchivingEnabled&&chatmarker!=ChatMarker.TYPE.NONE)) {
/* OF-677 - Workaround to prevent null messages being archived */
messageArchiver.archive( new ArchivedMessage(conversation.getConversationID(), sender, jid, date, body, roomArchivingStanzasEnabled ? stanza : "", false, receiverIfPM));
}
Expand Down
62 changes: 57 additions & 5 deletions src/java/org/jivesoftware/openfire/archive/ConversationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,13 @@ private ByteArrayOutputStream buildPDFContent(Conversation conversation, Map<JID
String prefix;

if (!message.isRoomEvent()) {
/*
* If body is null, then it is a chatmarker, so we add the ressource to see which device has sent the marker.
* */
if (to == null) {
prefix = "[" + time + "] " + from + ": ";
prefix = "[" + time + "] " + from+(body==null?(" ("+message.getToJID().getResource()+")"):"")+ ": ";
} else {
prefix = "[" + time + "] " + from + " -> " + to + ": ";
prefix = "[" + time + "] " + from+(body==null?(" ("+message.getToJID().getResource()+")"):"")+ " -> " + to + ": ";
}
Color color = colorMap.get(message.getFromJID());
if (color == null) {
Expand All @@ -230,12 +233,35 @@ private ByteArrayOutputStream buildPDFContent(Conversation conversation, Map<JID
}

messageParagraph.add(new Text(prefix).setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD)).setFontColor(color));
messageParagraph.add(new Text(body).setFontColor(ColorConstants.BLACK));
messageParagraph.add(new Text(body==null?"":body).setFontColor(ColorConstants.BLACK));
}
else {
prefix = "[" + time + "] ";
messageParagraph.add( new Text(prefix)).setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_OBLIQUE)).setFontColor(ColorConstants.MAGENTA);
messageParagraph.add( new Text(body).setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_OBLIQUE)).setFontColor(ColorConstants.MAGENTA));
messageParagraph.add( new Text(body==null?"":body).setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_OBLIQUE)).setFontColor(ColorConstants.MAGENTA));
}

if (body==null)
{
ChatMarker.TYPE chatmarker = ChatMarker.searchForXep0333(message.getStanza());
switch (chatmarker)
{
case NONE:
messageParagraph.add("--unknown message--");
break;
case MARKABLE:
messageParagraph.add("--message markable--");
break;
case RECEIVED:
messageParagraph.add("--message received--");
break;
case DISPLAYED:
messageParagraph.add("--message displayed--");
break;
case ACKNOWLEGED:
messageParagraph.add("--message acknowleged--");
break;
}
}
messageParagraph.add(new Text("\n"));
}
Expand Down Expand Up @@ -305,10 +331,36 @@ private ConversationInfo toConversationInfo(Conversation conversation,
if (conversation.getRoom() != null) {
from = message.getToJID().getResource();
}
from = StringUtils.escapeHTMLTags(from);
/*
* If body is null, then it is a chatmarker, so we add the ressource to see which device has sent the marker.
* */
from = StringUtils.escapeHTMLTags(from)+(message.getBody()==null?(" ("+message.getFromJID().getResource()+")"):"");
to = to == null ? null : StringUtils.escapeHTMLTags(to);
String cssLabel = cssLabels.get(message.getFromJID().toBareJID());
String body = StringUtils.escapeHTMLTags(message.getBody());

if (body==null)
{
ChatMarker.TYPE chatmarker = ChatMarker.searchForXep0333(message.getStanza());
switch (chatmarker)
{
case NONE:
body="--unknown message--";
break;
case MARKABLE:
body="--message markable--";
break;
case RECEIVED:
body="--message received--";
break;
case DISPLAYED:
body="--message displayed--";
break;
case ACKNOWLEGED:
body="--message acknowleged--";
break;
}
}
builder.append("<tr valign=top>");
if (!message.isRoomEvent()) {
builder.append("<td width=1% nowrap class=" + cssLabel + ">").append("[").append(time).append("]").append("</td>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,25 @@ public void messageReceived(JID roomJID, JID user, String nickname, Message mess
conversationManager.getRoomsArchived().isEmpty() ||
conversationManager.getRoomsArchived().contains(roomJID.getNode()));

ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID),
if (withBody)
{
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID),
ConversationEvent.roomMessageReceived(roomJID, user, null, nickname, withBody ? message.getBody() : null, message.toXML(), now));
}
else
{
String stanza = message.toXML();
ChatMarker.TYPE markertype = ChatMarker.searchForXep0333(stanza);

if (markertype!=ChatMarker.TYPE.NONE)
{
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID),
ConversationEvent.chatmarkerMessageReceived(roomJID, user, markertype,stanza,
new Date()));
}
}
}
}

Expand Down
Loading

0 comments on commit 50bc9f2

Please sign in to comment.