Skip to content

Commit 50bc9f2

Browse files
committed
xep333 rebased
1 parent 8a0edc1 commit 50bc9f2

File tree

8 files changed

+206
-11
lines changed

8 files changed

+206
-11
lines changed

src/i18n/monitoring_i18n.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ archive.settings.cancel = Cancel
9191
archive.settings.rebuild = Rebuild Index
9292
archive.settings.any = Any
9393
archive.settings.one_to_one=Archive one-to-one chats
94+
archive.settings.chatmarker=Archive chatmarkers (XEP-0333)
9495
archive.settings.group_chats=Archive group chats
9596
archive.settings.group_chats.stanzas=Archive stanzas for group chats
9697
archive.settings.certain_rooms=Only archive conversations of the following room names (separated by comma)

src/java/org/jivesoftware/openfire/archive/ArchiveInterceptor.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
2222
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
2323
import org.jivesoftware.openfire.session.Session;
24+
import org.jivesoftware.util.JiveGlobals;
2425
import org.xmpp.packet.JID;
2526
import org.xmpp.packet.Message;
2627
import org.xmpp.packet.Packet;
@@ -63,7 +64,7 @@ public void interceptPacket(Packet packet, Session session, boolean incoming, bo
6364
// Ignore any messages that don't have a body so that we skip events.
6465
// Note: XHTML messages should always include a body so we should be ok. It's
6566
// possible that we may need special XHTML filtering in the future, however.
66-
if (message.getBody() != null) {
67+
if (message.getBody() != null||(message.getBody()==null&&JiveGlobals.getBooleanProperty("conversation.chatmarkerArchiving", false))) {
6768
// Only process messages that are between two users, group chat rooms, or gateways.
6869
if (conversationManager.isConversation(message)) {
6970
// Process this event in the senior cluster member or local JVM when not in a cluster
@@ -74,11 +75,28 @@ public void interceptPacket(Packet packet, Session session, boolean incoming, bo
7475
JID sender = message.getFrom();
7576
JID receiver = message.getTo();
7677
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
77-
eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver),
78+
79+
if (message.getBody()!=null)
80+
{
81+
eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver),
7882
ConversationEvent.chatMessageReceived(sender, receiver,
7983
conversationManager.isMessageArchivingEnabled() ? message.getBody() : null,
8084
conversationManager.isMessageArchivingEnabled() ? message.toXML() : null,
8185
new Date()));
86+
}
87+
else
88+
{
89+
String stanza = message.toXML();
90+
ChatMarker.TYPE markertype = ChatMarker.searchForXep0333(stanza);
91+
92+
if (markertype!=ChatMarker.TYPE.NONE)
93+
{
94+
eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver),
95+
ConversationEvent.chatmarkerMessageReceived(sender, receiver,markertype,
96+
conversationManager.isMessageArchivingEnabled() ? message.toXML() : null,
97+
new Date()));
98+
}
99+
}
82100
}
83101
}
84102
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.jivesoftware.openfire.archive;
2+
3+
public class ChatMarker {
4+
5+
public enum TYPE
6+
{
7+
NONE,
8+
MARKABLE,
9+
RECEIVED,
10+
DISPLAYED,
11+
ACKNOWLEGED;
12+
}
13+
14+
public static TYPE searchForXep0333(String stanza)
15+
{
16+
if (stanza==null)
17+
{
18+
return TYPE.NONE;
19+
}
20+
21+
int idxmarkable = stanza.indexOf("<markable");
22+
int idxreceived= stanza.indexOf("<received");
23+
int idxdisplayed = stanza.indexOf("<displayed");
24+
int idxacknowled = stanza.indexOf("<acknowledged");
25+
26+
if (idxmarkable!=-1)
27+
{
28+
int idxEnd = stanza.indexOf("/>",idxmarkable);
29+
if (idxEnd==-1)
30+
{
31+
idxEnd = stanza.indexOf("</markable>",idxmarkable);
32+
}
33+
return idxEnd!=-1?(stanza.substring(idxmarkable, idxEnd).contains("urn:xmpp:chat-markers:0")?TYPE.MARKABLE:TYPE.NONE):TYPE.NONE;
34+
}
35+
else
36+
if (idxreceived!=-1)
37+
{
38+
int idxEnd = stanza.indexOf("/>",idxreceived);
39+
if (idxEnd==-1)
40+
{
41+
idxEnd = stanza.indexOf("</received>",idxmarkable);
42+
}
43+
return idxEnd!=-1?(stanza.substring(idxreceived, idxEnd).contains("urn:xmpp:chat-markers:0")?TYPE.RECEIVED:TYPE.NONE):TYPE.NONE;
44+
}
45+
else
46+
if (idxdisplayed!=-1)
47+
{
48+
int idxEnd = stanza.indexOf("/>",idxdisplayed);
49+
if (idxEnd==-1)
50+
{
51+
idxEnd = stanza.indexOf("</displayed>",idxmarkable);
52+
}
53+
return idxEnd!=-1?(stanza.substring(idxdisplayed, idxEnd).contains("urn:xmpp:chat-markers:0")?TYPE.DISPLAYED:TYPE.NONE):TYPE.NONE;
54+
}
55+
else
56+
if (idxacknowled!=-1)
57+
{
58+
int idxEnd = stanza.indexOf("/>",idxacknowled);
59+
if (idxEnd==-1)
60+
{
61+
idxEnd = stanza.indexOf("</acknowledged>",idxmarkable);
62+
}
63+
return idxEnd!=-1?(stanza.substring(idxacknowled, idxEnd).contains("urn:xmpp:chat-markers:0")?TYPE.ACKNOWLEGED:TYPE.NONE):TYPE.NONE;
64+
}
65+
else
66+
return TYPE.NONE;
67+
}
68+
}

src/java/org/jivesoftware/openfire/archive/ConversationEvent.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ConversationEvent implements Externalizable {
3838
private Date date;
3939
private String body;
4040
private String stanza;
41+
private ChatMarker.TYPE marker;
4142

4243
private JID sender;
4344
private JID receiver;
@@ -147,6 +148,16 @@ public static ConversationEvent chatMessageReceived(JID sender, JID receiver, St
147148
event.sender = sender;
148149
event.receiver = receiver;
149150
event.body = body;
151+
event.date = date;
152+
return event;
153+
}
154+
155+
public static ConversationEvent chatmarkerMessageReceived(JID sender, JID receiver, ChatMarker.TYPE marker, String stanza, Date date) {
156+
ConversationEvent event = new ConversationEvent();
157+
event.type = Type.chatMessageReceived;
158+
event.sender = sender;
159+
event.receiver = receiver;
160+
event.marker = marker;
150161
event.stanza = stanza;
151162
event.date = date;
152163
return event;

src/java/org/jivesoftware/openfire/archive/ConversationManager.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public class ConversationManager implements ComponentEventListener{
104104
*/
105105
private boolean roomArchivingEnabled;
106106
private boolean roomArchivingStanzasEnabled;
107+
108+
private boolean chatmarkerArchivingEnabled;
109+
107110
/**
108111
* List of room names to archive. When list is empty then all rooms are archived (if roomArchivingEnabled is enabled).
109112
*/
@@ -143,6 +146,9 @@ public void start() {
143146
Log.warn("Metadata archiving must be enabled when message archiving is enabled. Overriding setting.");
144147
metadataArchivingEnabled = true;
145148
}
149+
150+
chatmarkerArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.chatmarkerArchiving", false);
151+
146152
roomArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchiving", false);
147153
roomArchivingStanzasEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchivingStanzas", false);
148154
roomsArchived = StringUtils.stringToCollection(JiveGlobals.getProperty("conversation.roomsArchived", ""));
@@ -269,6 +275,15 @@ public boolean isPartialSample() {
269275
InternalComponentManager.getInstance().addListener(this);
270276
}
271277

278+
public boolean isChatmarkerArchivingEnabled() {
279+
return chatmarkerArchivingEnabled;
280+
}
281+
282+
public void setChatmarkerArchivingEnabled(boolean chatmarkerArchivingEnabled) {
283+
this.chatmarkerArchivingEnabled = chatmarkerArchivingEnabled;
284+
JiveGlobals.setProperty("conversation.chatmarkerArchiving", Boolean.toString(chatmarkerArchivingEnabled));
285+
}
286+
272287
public void stop() {
273288
cleanupTask.cancel();
274289
cleanupTask = null;
@@ -643,6 +658,9 @@ public void removeConversationListener(ConversationListener listener) {
643658
void processMessage(JID sender, JID receiver, String body, String stanza, Date date) {
644659
Log.trace("Processing message from date {}...", date );
645660
String conversationKey = getConversationKey(sender, receiver);
661+
662+
ChatMarker.TYPE chatmarker=ChatMarker.searchForXep0333(stanza);
663+
646664
synchronized (conversationKey.intern()) {
647665
Conversation conversation = conversations.get(conversationKey);
648666
// Create a new conversation if necessary.
@@ -693,7 +711,7 @@ else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime)
693711
conversationArchiver.archive(conversation);
694712
}
695713
if (messageArchivingEnabled) {
696-
if (body != null) {
714+
if (body != null||(body==null&&chatmarkerArchivingEnabled&&chatmarker!=ChatMarker.TYPE.NONE)) {
697715
/* OF-677 - Workaround to prevent null messages being archived */
698716
messageArchiver.archive(new ArchivedMessage(conversation.getConversationID(), sender, receiver, date, body, stanza, false, null) );
699717
}
@@ -725,6 +743,9 @@ else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime)
725743
void processRoomMessage(JID roomJID, JID sender, JID receiverIfPM, String nickname, String body, String stanza, Date date) {
726744
Log.trace("Processing room {} message from date {}.", roomJID, date );
727745
String conversationKey = getRoomConversationKey(roomJID);
746+
747+
ChatMarker.TYPE chatmarker=ChatMarker.searchForXep0333(stanza);
748+
728749
synchronized (conversationKey.intern()) {
729750
Conversation conversation = conversations.get(conversationKey);
730751
// Create a new conversation if necessary.
@@ -759,7 +780,7 @@ else if ((date.getTime() - conversation.getLastActivity().getTime() > idleTime)
759780
}
760781
if (roomArchivingEnabled && (roomsArchived.isEmpty() || roomsArchived.contains(roomJID.getNode()))) {
761782
JID jid = new JID(roomJID + "/" + nickname);
762-
if (body != null) {
783+
if (body != null||(body==null&&chatmarkerArchivingEnabled&&chatmarker!=ChatMarker.TYPE.NONE)) {
763784
/* OF-677 - Workaround to prevent null messages being archived */
764785
messageArchiver.archive( new ArchivedMessage(conversation.getConversationID(), sender, jid, date, body, roomArchivingStanzasEnabled ? stanza : "", false, receiverIfPM));
765786
}

src/java/org/jivesoftware/openfire/archive/ConversationUtils.java

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,13 @@ private ByteArrayOutputStream buildPDFContent(Conversation conversation, Map<JID
216216
String prefix;
217217

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

232235
messageParagraph.add(new Text(prefix).setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD)).setFontColor(color));
233-
messageParagraph.add(new Text(body).setFontColor(ColorConstants.BLACK));
236+
messageParagraph.add(new Text(body==null?"":body).setFontColor(ColorConstants.BLACK));
234237
}
235238
else {
236239
prefix = "[" + time + "] ";
237240
messageParagraph.add( new Text(prefix)).setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_OBLIQUE)).setFontColor(ColorConstants.MAGENTA);
238-
messageParagraph.add( new Text(body).setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_OBLIQUE)).setFontColor(ColorConstants.MAGENTA));
241+
messageParagraph.add( new Text(body==null?"":body).setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_OBLIQUE)).setFontColor(ColorConstants.MAGENTA));
242+
}
243+
244+
if (body==null)
245+
{
246+
ChatMarker.TYPE chatmarker = ChatMarker.searchForXep0333(message.getStanza());
247+
switch (chatmarker)
248+
{
249+
case NONE:
250+
messageParagraph.add("--unknown message--");
251+
break;
252+
case MARKABLE:
253+
messageParagraph.add("--message markable--");
254+
break;
255+
case RECEIVED:
256+
messageParagraph.add("--message received--");
257+
break;
258+
case DISPLAYED:
259+
messageParagraph.add("--message displayed--");
260+
break;
261+
case ACKNOWLEGED:
262+
messageParagraph.add("--message acknowleged--");
263+
break;
264+
}
239265
}
240266
messageParagraph.add(new Text("\n"));
241267
}
@@ -305,10 +331,36 @@ private ConversationInfo toConversationInfo(Conversation conversation,
305331
if (conversation.getRoom() != null) {
306332
from = message.getToJID().getResource();
307333
}
308-
from = StringUtils.escapeHTMLTags(from);
334+
/*
335+
* If body is null, then it is a chatmarker, so we add the ressource to see which device has sent the marker.
336+
* */
337+
from = StringUtils.escapeHTMLTags(from)+(message.getBody()==null?(" ("+message.getFromJID().getResource()+")"):"");
309338
to = to == null ? null : StringUtils.escapeHTMLTags(to);
310339
String cssLabel = cssLabels.get(message.getFromJID().toBareJID());
311340
String body = StringUtils.escapeHTMLTags(message.getBody());
341+
342+
if (body==null)
343+
{
344+
ChatMarker.TYPE chatmarker = ChatMarker.searchForXep0333(message.getStanza());
345+
switch (chatmarker)
346+
{
347+
case NONE:
348+
body="--unknown message--";
349+
break;
350+
case MARKABLE:
351+
body="--message markable--";
352+
break;
353+
case RECEIVED:
354+
body="--message received--";
355+
break;
356+
case DISPLAYED:
357+
body="--message displayed--";
358+
break;
359+
case ACKNOWLEGED:
360+
body="--message acknowleged--";
361+
break;
362+
}
363+
}
312364
builder.append("<tr valign=top>");
313365
if (!message.isRoomEvent()) {
314366
builder.append("<td width=1% nowrap class=" + cssLabel + ">").append("[").append(time).append("]").append("</td>");

src/java/org/jivesoftware/openfire/archive/GroupConversationInterceptor.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,25 @@ public void messageReceived(JID roomJID, JID user, String nickname, Message mess
124124
conversationManager.getRoomsArchived().isEmpty() ||
125125
conversationManager.getRoomsArchived().contains(roomJID.getNode()));
126126

127-
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
128-
eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID),
127+
if (withBody)
128+
{
129+
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
130+
eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID),
129131
ConversationEvent.roomMessageReceived(roomJID, user, null, nickname, withBody ? message.getBody() : null, message.toXML(), now));
132+
}
133+
else
134+
{
135+
String stanza = message.toXML();
136+
ChatMarker.TYPE markertype = ChatMarker.searchForXep0333(stanza);
137+
138+
if (markertype!=ChatMarker.TYPE.NONE)
139+
{
140+
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
141+
eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID),
142+
ConversationEvent.chatmarkerMessageReceived(roomJID, user, markertype,stanza,
143+
new Date()));
144+
}
145+
}
130146
}
131147
}
132148

0 commit comments

Comments
 (0)