Commit abcfd631 authored by Sebastian Wissen's avatar Sebastian Wissen

add possibility to store complete stanza in archive

in the settings there is now a switch allowing to add complete stanza to
the archive for muc conversations
parent 010973b0
......@@ -95,6 +95,7 @@ archive.settings.rebuild = Rebuild Index
archive.settings.any = Any
archive.settings.one_to_one=Archive one-to-one chats
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)
archive.search.title = Search Archive
......
......@@ -40,6 +40,7 @@ public class ConversationEvent implements Externalizable {
private Type type;
private Date date;
private String body;
private String stanza;
private JID sender;
private JID receiver;
......@@ -77,7 +78,7 @@ public class ConversationEvent implements Externalizable {
conversationManager.joinedGroupConversation(roomJID, user, nickname, new Date(date.getTime() + 1));
}
else if (Type.roomMessageReceived == type) {
conversationManager.processRoomMessage(roomJID, user, nickname, body, date);
conversationManager.processRoomMessage(roomJID, user, nickname, body, stanza, date);
}
}
......@@ -185,13 +186,14 @@ public class ConversationEvent implements Externalizable {
}
public static ConversationEvent roomMessageReceived(JID roomJID, JID user, String nickname, String body,
Date date) {
String stanza, Date date) {
ConversationEvent event = new ConversationEvent();
event.type = Type.roomMessageReceived;
event.roomJID = roomJID;
event.user = user;
event.nickname = nickname;
event.body = body;
event.stanza = stanza;
event.date = date;
return event;
}
......
......@@ -115,6 +115,7 @@ public class ConversationManager implements Startable, ComponentEventListener{
* Flag that indicates if messages of group chats (in MUC rooms) should be archived.
*/
private boolean roomArchivingEnabled;
private boolean roomArchivingStanzasEnabled;
/**
* List of room names to archive. When list is empty then all rooms are archived (if roomArchivingEnabled is enabled).
*/
......@@ -162,6 +163,7 @@ public class ConversationManager implements Startable, ComponentEventListener{
metadataArchivingEnabled = true;
}
roomArchivingEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchiving", false);
roomArchivingStanzasEnabled = JiveGlobals.getBooleanProperty("conversation.roomArchivingStanzas", false);
roomsArchived = StringUtils.stringToCollection(JiveGlobals.getProperty("conversation.roomsArchived", ""));
if (roomArchivingEnabled && !metadataArchivingEnabled) {
Log.warn("Metadata archiving must be enabled when room archiving is enabled. Overriding setting.");
......@@ -391,6 +393,11 @@ public class ConversationManager implements Startable, ComponentEventListener{
return roomArchivingEnabled;
}
public boolean isRoomArchivingStanzasEnabled() {
return roomArchivingStanzasEnabled;
}
/**
* Sets whether message archiving is enabled for group chats. When enabled, all messages in group conversations are stored in the database unless
* a list of rooms was specified in {@link #getRoomsArchived()} . Note: it's not possible for meta-data archiving to be disabled when room
......@@ -407,7 +414,12 @@ public class ConversationManager implements Startable, ComponentEventListener{
this.metadataArchivingEnabled = true;
}
}
public void setRoomArchivingStanzasEnabled(boolean enabled) {
this.roomArchivingStanzasEnabled = enabled;
JiveGlobals.setProperty("conversation.roomArchivingStanzas", Boolean.toString(enabled));
// Force metadata archiving enabled.
}
/**
* Returns list of room names whose messages will be archived. When room archiving is enabled and this list is empty then messages of all local
* rooms will be archived. However, when name of rooms are defined in this list then only messages of those rooms will be archived.
......@@ -738,7 +750,7 @@ public class ConversationManager implements Startable, ComponentEventListener{
* @param date
* date when the message was sent.
*/
void processRoomMessage(JID roomJID, JID sender, String nickname, String body, Date date) {
void processRoomMessage(JID roomJID, JID sender, String nickname, String body, String stanza, Date date) {
String conversationKey = getRoomConversationKey(roomJID);
synchronized (conversationKey.intern()) {
Conversation conversation = conversations.get(conversationKey);
......@@ -776,7 +788,7 @@ public class ConversationManager implements Startable, ComponentEventListener{
JID jid = new JID(roomJID + "/" + nickname);
if (body != null) {
/* OF-677 - Workaround to prevent null messages being archived */
messageQueue.add(new ArchivedMessage(conversation.getConversationID(), sender, jid, date, body, "", false));
messageQueue.add(new ArchivedMessage(conversation.getConversationID(), sender, jid, date, body, roomArchivingStanzasEnabled ? stanza : "", false));
}
}
// Notify listeners of the conversation update.
......@@ -1094,6 +1106,9 @@ public class ConversationManager implements Startable, ComponentEventListener{
if (roomArchivingEnabled) {
metadataArchivingEnabled = true;
}
} else if( property.equals( "conversation.roomArchivingStanzas" ) ) {
String value = (String) params.get( "value" );
roomArchivingStanzasEnabled = Boolean.valueOf( value );
} else if (property.equals("conversation.roomsArchived")) {
String value = (String) params.get("value");
roomsArchived = StringUtils.stringToCollection(value);
......@@ -1149,6 +1164,8 @@ public class ConversationManager implements Startable, ComponentEventListener{
messageArchivingEnabled = false;
} else if (property.equals("conversation.roomArchiving")) {
roomArchivingEnabled = false;
} else if (property.equals("conversation.roomArchivingStanzas")) {
roomArchivingStanzasEnabled = false;
} else if (property.equals("conversation.roomsArchived")) {
roomsArchived = Collections.emptyList();
} else if (property.equals("conversation.idleTime")) {
......
......@@ -112,7 +112,7 @@ public class GroupConversationInterceptor implements MUCEventListener, Startable
public void messageReceived(JID roomJID, JID user, String nickname, Message message) {
// Process this event in the senior cluster member or local JVM when not in a cluster
if (ClusterManager.isSeniorClusterMember()) {
conversationManager.processRoomMessage(roomJID, user, nickname, message.getBody(), new Date());
conversationManager.processRoomMessage(roomJID, user, nickname, message.getBody(), message.toXML(), new Date());
}
else {
boolean withBody = conversationManager.isRoomArchivingEnabled() && (
......@@ -121,7 +121,7 @@ public class GroupConversationInterceptor implements MUCEventListener, Startable
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
eventsQueue.addGroupChatEvent(conversationManager.getRoomConversationKey(roomJID),
ConversationEvent.roomMessageReceived(roomJID, user, nickname, withBody ? message.getBody() : null, new Date()));
ConversationEvent.roomMessageReceived(roomJID, user, nickname, withBody ? message.getBody() : null, message.toXML(), new Date()));
}
}
......
......@@ -161,6 +161,7 @@
boolean update = request.getParameter("update") != null;
boolean messageArchiving = conversationManager.isMessageArchivingEnabled();
boolean roomArchiving = conversationManager.isRoomArchivingEnabled();
boolean roomArchivingStanzas = conversationManager.isRoomArchivingStanzasEnabled();
int idleTime = ParamUtils.getIntParameter(request, "idleTime", conversationManager.getIdleTime());
int maxTime = ParamUtils.getIntParameter(request, "maxTime", conversationManager.getMaxTime());
......@@ -186,6 +187,7 @@
boolean metadataArchiving = request.getParameter("metadataArchiving") != null;
messageArchiving = request.getParameter("messageArchiving") != null;
roomArchiving = request.getParameter("roomArchiving") != null;
roomArchivingStanzas = request.getParameter("roomArchivingStanzas") != null;
String roomsArchived = request.getParameter("roomsArchived");
// Validate params
......@@ -214,6 +216,7 @@
conversationManager.setMetadataArchivingEnabled(metadataArchiving);
conversationManager.setMessageArchivingEnabled(messageArchiving);
conversationManager.setRoomArchivingEnabled(roomArchiving);
conversationManager.setRoomArchivingStanzasEnabled(roomArchivingStanzas);
conversationManager.setRoomsArchived(StringUtils.stringToCollection(roomsArchived));
conversationManager.setIdleTime(idleTime);
conversationManager.setMaxTime(maxTime);
......@@ -281,6 +284,10 @@
<td><fmt:message key="archive.settings.group_chats"/></td>
<td><input type="checkbox" name="roomArchiving" <%= conversationManager.isRoomArchivingEnabled() ? "checked" : ""%> /></td>
</tr>
<tr>
<td><fmt:message key="archive.settings.group_chats.stanzas"/></td>
<td><input type="checkbox" name="roomArchivingStanzas" <%= conversationManager.isRoomArchivingStanzasEnabled() ? "checked" : ""%> /></td>
</tr>
<tr>
<td><fmt:message key="archive.settings.certain_rooms"/></td>
<td><textarea name="roomsArchived" cols="30" rows="2" wrap="virtual"><%= StringUtils.collectionToString(conversationManager.getRoomsArchived()) %></textarea></td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment