Commit 7ec010be authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Refactoring work.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@593 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7d1390b1
...@@ -22,6 +22,8 @@ import java.util.TimeZone; ...@@ -22,6 +22,8 @@ import java.util.TimeZone;
import org.jivesoftware.messenger.muc.spi.MUCRoleImpl; import org.jivesoftware.messenger.muc.spi.MUCRoleImpl;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.dom4j.Element;
import org.xmpp.packet.Message;
/** /**
* Represents the amount of history requested by an occupant while joining a room. There are * Represents the amount of history requested by an occupant while joining a room. There are
...@@ -48,21 +50,22 @@ public class HistoryRequest { ...@@ -48,21 +50,22 @@ public class HistoryRequest {
private int seconds = -1; private int seconds = -1;
private Date since; private Date since;
public HistoryRequest(MetaDataFragment userFragment) { public HistoryRequest(Element userFragment) {
if (userFragment.includesProperty("x.history")) { Element history = userFragment.element("history");
if (userFragment.includesProperty("x.history:maxchars")) { if (history != null) {
this.maxChars = Integer.parseInt(userFragment.getProperty("x.history:maxchars")); if (history.attribute("maxchars") != null) {
this.maxChars = Integer.parseInt(history.attributeValue("maxchars"));
} }
if (userFragment.includesProperty("x.history:maxstanzas")) { if (history.attribute("maxstanzas") != null) {
this.maxStanzas = Integer.parseInt(userFragment.getProperty("x.history:maxstanzas")); this.maxStanzas = Integer.parseInt(history.attributeValue("maxstanzas"));
} }
if (userFragment.includesProperty("x.history:seconds")) { if (history.attribute("seconds") != null) {
this.seconds = Integer.parseInt(userFragment.getProperty("x.history:seconds")); this.seconds = Integer.parseInt(history.attributeValue("seconds"));
} }
if (userFragment.includesProperty("x.history:since")) { if (history.attribute("since") != null) {
try { try {
// parse utc into Date // parse utc into Date
this.since = formatter.parse(userFragment.getProperty("x.history:since")); this.since = formatter.parse(history.attributeValue("since"));
} }
catch(ParseException pe) { catch(ParseException pe) {
Log.error("Error parsing date from history management", pe); Log.error("Error parsing date from history management", pe);
...@@ -142,7 +145,7 @@ public class HistoryRequest { ...@@ -142,7 +145,7 @@ public class HistoryRequest {
Message message; Message message;
int accumulatedChars = 0; int accumulatedChars = 0;
int accumulatedStanzas = 0; int accumulatedStanzas = 0;
MetaDataFragment delayInformation; Element delayInformation;
LinkedList historyToSend = new LinkedList(); LinkedList historyToSend = new LinkedList();
ListIterator iterator = roomHistory.getReverseMessageHistory(); ListIterator iterator = roomHistory.getReverseMessageHistory();
while (iterator.hasPrevious()) { while (iterator.hasPrevious()) {
...@@ -161,13 +164,10 @@ public class HistoryRequest { ...@@ -161,13 +164,10 @@ public class HistoryRequest {
} }
if (getSeconds() > -1 || getSince() != null) { if (getSeconds() > -1 || getSince() != null) {
delayInformation = (MetaDataFragment) message.getFragment( delayInformation = message.getChildElement("x", "jabber:x:delay");
"x",
"jabber:x:delay");
try { try {
// Get the date when the historic message was sent // Get the date when the historic message was sent
Date delayedDate = delayedFormatter.parse(delayInformation Date delayedDate = delayedFormatter.parse(delayInformation.attributeValue("stamp"));
.getProperty("x:stamp"));
if (getSince() != null && delayedDate.before(getSince())) { if (getSince() != null && delayedDate.before(getSince())) {
// Stop collecting history since we have exceded a limit // Stop collecting history since we have exceded a limit
break; break;
......
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