Commit f25447b3 authored by Dave Cridland's avatar Dave Cridland

OF-817 Persist entire MUC stanza

parent 45fb7ff9
......@@ -265,7 +265,8 @@ CREATE TABLE ofMucConversationLog (
nickname VARCHAR(255),
logTime CHAR(15) NOT NULL,
subject VARCHAR(255),
body CLOB
body CLOB,
stanza CLOB
);
CREATE INDEX ofMucConvLog_time_idx ON ofMucConversationLog (logTime);
......
......@@ -257,7 +257,8 @@ CREATE TABLE ofMucConversationLog (
nickname VARCHAR(255) NULL,
logTime CHAR(15) NOT NULL,
subject VARCHAR(255) NULL,
body LONGVARCHAR NULL
body LONGVARCHAR NULL,
stanza LONGVARCHAR NULL
);
CREATE INDEX ofMucConversationLog_time_idx ON ofMucConversationLog (logTime);
......
......@@ -247,6 +247,7 @@ CREATE TABLE ofMucConversationLog (
logTime CHAR(15) NOT NULL,
subject VARCHAR(255) NULL,
body TEXT NULL,
stanza TEXT NULL,
INDEX ofMucConversationLog_time_idx (logTime)
);
......
......@@ -254,7 +254,8 @@ CREATE TABLE ofMucConversationLog (
nickname VARCHAR2(255) NULL,
logTime CHAR(15) NOT NULL,
subject VARCHAR2(255) NULL,
body VARCHAR2(4000) NULL
body VARCHAR2(4000) NULL,
stanza VARCHAR2(4000) NULL
);
CREATE INDEX ofMucConversationLog_time_idx ON ofMucConversationLog (logTime);
......
......@@ -262,7 +262,8 @@ CREATE TABLE ofMucConversationLog (
nickname VARCHAR(255) NULL,
logTime CHAR(15) NOT NULL,
subject VARCHAR(255) NULL,
body TEXT NULL
body TEXT NULL,
stanza TEXT NULL
);
CREATE INDEX ofMucConversationLog_time_idx ON ofMucConversationLog (logTime);
......
......@@ -260,7 +260,8 @@ CREATE TABLE ofMucConversationLog (
nickname NVARCHAR(255) NULL,
logTime CHAR(15) NOT NULL,
subject NVARCHAR(255) NULL,
body NTEXT NULL
body NTEXT NULL,
stanza NTEXT NULL
);
CREATE INDEX ofMucConversationLog_time_idx ON ofMucConversationLog (logTime);
......
......@@ -260,7 +260,8 @@ CREATE TABLE ofMucConversationLog (
nickname NVARCHAR(255) NULL,
logTime CHAR(15) NOT NULL,
subject NVARCHAR(255) NULL,
body TEXT NULL
body TEXT NULL,
stanza TEXT NULL
);
CREATE INDEX ofMucConversationLog_time_idx ON ofMucConversationLog (logTime);
......
......@@ -20,14 +20,19 @@
package org.jivesoftware.openfire.muc;
import org.dom4j.Attribute;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.io.SAXReader;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.XMPPDateTimeFormat;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import java.io.StringReader;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
/**
......@@ -147,10 +152,33 @@ public final class MUCRoomHistory {
* @param body the body of the message.
*/
public void addOldMessage(String senderJID, String nickname, Date sentDate, String subject,
String body)
String body, String stanza)
{
Message message = new Message();
message.setType(Message.Type.groupchat);
if (stanza != null) {
// payload initialized as XML string from DB
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
try {
Element element = xmlReader.read(new StringReader(stanza)).getRootElement();
for (Element child : (List<Element>)element.elements()) {
Namespace ns = child.getNamespace();
if (ns == null || ns.getURI().equals("jabber:client") || ns.getURI().equals("jabber:server")) {
continue;
}
Element added = message.addChildElement(child.getName(), child.getNamespaceURI());
for (Attribute attr : (List<Attribute>)child.attributes()) {
added.add(attr);
}
for (Element el : (List<Element>)child.elements()) {
added.add(el);
}
}
} catch (Exception ex) {
// log.error("Failed to parse payload XML", ex);
}
}
message.setSubject(subject);
message.setBody(body);
// Set the sender of the message
......
......@@ -45,6 +45,8 @@ class ConversationLogEntry {
private final JID sender;
private final String nickname;
private final String stanza;
private final long roomID;
......@@ -61,6 +63,7 @@ class ConversationLogEntry {
this.date = date;
this.subject = message.getSubject();
this.body = message.getBody();
this.stanza = message.toString();
this.sender = sender;
this.roomID = room.getID();
this.nickname = message.getFrom().getResource();
......@@ -120,4 +123,10 @@ class ConversationLogEntry {
return roomID;
}
/**
* Returns the string representation of the message.
*
* @return string representation of the stanza.
*/
public String getStanza() { return stanza; }
}
\ No newline at end of file
......@@ -69,7 +69,7 @@ public class MUCPersistenceManager {
private static final String LOAD_MEMBERS =
"SELECT jid, nickname FROM ofMucMember WHERE roomID=?";
private static final String LOAD_HISTORY =
"SELECT sender, nickname, logTime, subject, body FROM ofMucConversationLog " +
"SELECT sender, nickname, logTime, subject, body, stanza FROM ofMucConversationLog " +
"WHERE logTime>? AND roomID=? AND (nickname IS NOT NULL OR subject IS NOT NULL) ORDER BY logTime";
private static final String LOAD_ALL_ROOMS =
"SELECT roomID, creationDate, modificationDate, name, naturalName, description, " +
......@@ -85,7 +85,7 @@ public class MUCPersistenceManager {
"WHERE ofMucMember.roomID = ofMucRoom.roomID AND ofMucRoom.serviceID=?";
private static final String LOAD_ALL_HISTORY =
"SELECT ofMucConversationLog.roomID, ofMucConversationLog.sender, ofMucConversationLog.nickname, " +
"ofMucConversationLog.logTime, ofMucConversationLog.subject, ofMucConversationLog.body FROM " +
"ofMucConversationLog.logTime, ofMucConversationLog.subject, ofMucConversationLog.body, ofMucConversationLog.stanza FROM " +
"ofMucConversationLog, ofMucRoom WHERE ofMucConversationLog.roomID = ofMucRoom.roomID AND " +
"ofMucRoom.serviceID=? AND ofMucConversationLog.logTime>? AND (ofMucConversationLog.nickname IS NOT NULL " +
"OR ofMucConversationLog.subject IS NOT NULL) ORDER BY ofMucConversationLog.logTime";
......@@ -129,8 +129,8 @@ public class MUCPersistenceManager {
private static final String DELETE_USER_MUCAFFILIATION =
"DELETE FROM ofMucAffiliation WHERE jid=?";
private static final String ADD_CONVERSATION_LOG =
"INSERT INTO ofMucConversationLog (roomID,sender,nickname,logTime,subject,body) " +
"VALUES (?,?,?,?,?,?)";
"INSERT INTO ofMucConversationLog (roomID,sender,nickname,logTime,subject,body,stanza) " +
"VALUES (?,?,?,?,?,?,?)";
/* Map of subdomains to their associated properties */
private static ConcurrentHashMap<String,MUCServiceProperties> propertyMaps = new ConcurrentHashMap<>();
......@@ -249,8 +249,9 @@ public class MUCPersistenceManager {
Date sentDate = new Date(Long.parseLong(rs.getString(3).trim()));
String subject = rs.getString(4);
String body = rs.getString(5);
String stanza = rs.getString(6);
room.getRoomHistory().addOldMessage(senderJID, nickname, sentDate, subject,
body);
body, stanza);
}
}
DbConnectionManager.fastcloseStmt(rs, pstmt);
......@@ -260,7 +261,7 @@ public class MUCPersistenceManager {
if (!room.getRoomHistory().hasChangedSubject() && room.getSubject() != null &&
room.getSubject().length() > 0) {
room.getRoomHistory().addOldMessage(room.getRole().getRoleAddress().toString(),
null, room.getModificationDate(), room.getSubject(), null);
null, room.getModificationDate(), room.getSubject(), null, null);
}
pstmt = con.prepareStatement(LOAD_AFFILIATIONS);
......@@ -599,7 +600,8 @@ public class MUCPersistenceManager {
Date sentDate = new Date(Long.parseLong(resultSet.getString(4).trim()));
String subject = resultSet.getString(5);
String body = resultSet.getString(6);
room.getRoomHistory().addOldMessage(senderJID, nickname, sentDate, subject, body);
String stanza = resultSet.getString(7);
room.getRoomHistory().addOldMessage(senderJID, nickname, sentDate, subject, body, stanza);
} catch (SQLException e) {
Log.warn("A database exception prevented the history for one particular MUC room to be loaded from the database.", e);
}
......@@ -620,6 +622,7 @@ public class MUCPersistenceManager {
null,
loadedRoom.getModificationDate(),
loadedRoom.getSubject(),
null,
null);
}
}
......@@ -1063,6 +1066,7 @@ public class MUCPersistenceManager {
pstmt.setString(4, StringUtils.dateToMillis(entry.getDate()));
pstmt.setString(5, entry.getSubject());
pstmt.setString(6, entry.getBody());
pstmt.setString(7, entry.getStanza());
pstmt.executeUpdate();
return true;
}
......
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