aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2012-07-16 16:15:38 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2012-07-16 16:15:38 +0200
commitda148da400d65db15e2749a7066b84c9bcbb9b43 (patch)
tree9401e058c7d4631d1aed816af61900f4f8613e04
parent99bd8884bc87fbdbbe3a053f3afda9155b914c0f (diff)
parent0ae287b2c624df43b3744f79911d11baa0699c68 (diff)
downloadqxmpp-da148da400d65db15e2749a7066b84c9bcbb9b43.tar.gz
Merge branch 'master' of https://code.google.com/p/qxmpp
-rw-r--r--src/base/QXmppArchiveIq.cpp11
-rw-r--r--tests/tests.cpp6
2 files changed, 14 insertions, 3 deletions
diff --git a/src/base/QXmppArchiveIq.cpp b/src/base/QXmppArchiveIq.cpp
index 8bc6b12d..068b4366 100644
--- a/src/base/QXmppArchiveIq.cpp
+++ b/src/base/QXmppArchiveIq.cpp
@@ -93,6 +93,8 @@ void QXmppArchiveChat::parse(const QDomElement &element)
m_thread = element.attribute("thread");
m_version = element.attribute("version").toInt();
+ QDateTime timeAccu = m_start;
+
QDomElement child = element.firstChildElement();
while (!child.isNull())
{
@@ -100,7 +102,8 @@ void QXmppArchiveChat::parse(const QDomElement &element)
{
QXmppArchiveMessage message;
message.setBody(child.firstChildElement("body").text());
- message.setDate(m_start.addSecs(child.attribute("secs").toInt()));
+ timeAccu = timeAccu.addSecs(child.attribute("secs").toInt());
+ message.setDate(timeAccu);
message.setReceived(child.tagName() == "from");
m_messages << message;
}
@@ -119,12 +122,16 @@ void QXmppArchiveChat::toXml(QXmlStreamWriter *writer) const
helperToXmlAddAttribute(writer, "thread", m_thread);
if (m_version)
helperToXmlAddAttribute(writer, "version", QString::number(m_version));
+
+ QDateTime prevTime = m_start;
+
foreach (const QXmppArchiveMessage &message, m_messages)
{
writer->writeStartElement(message.isReceived() ? "from" : "to");
- helperToXmlAddAttribute(writer, "secs", QString::number(m_start.secsTo(message.date())));
+ helperToXmlAddAttribute(writer, "secs", QString::number(prevTime.secsTo(message.date())));
writer->writeTextElement("body", message.body());
writer->writeEndElement();
+ prevTime = message.date();
}
writer->writeEndElement();
}
diff --git a/tests/tests.cpp b/tests/tests.cpp
index f67fbc4f..3a67fddc 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -224,6 +224,7 @@ void TestPackets::testArchiveChat()
">"
"<from secs=\"0\"><body>Art thou not Romeo, and a Montague?</body></from>"
"<to secs=\"11\"><body>Neither, fair saint, if either thee dislike.</body></to>"
+ "<from secs=\"7\"><body>How cam'st thou hither, tell me, and wherefore?</body></from>"
"</chat>"
"</iq>");
@@ -232,13 +233,16 @@ void TestPackets::testArchiveChat()
QCOMPARE(iq.type(), QXmppIq::Result);
QCOMPARE(iq.id(), QLatin1String("chat_1"));
QCOMPARE(iq.chat().with(), QLatin1String("juliet@capulet.com"));
- QCOMPARE(iq.chat().messages().size(), 2);
+ QCOMPARE(iq.chat().messages().size(), 3);
QCOMPARE(iq.chat().messages()[0].isReceived(), true);
QCOMPARE(iq.chat().messages()[0].body(), QLatin1String("Art thou not Romeo, and a Montague?"));
QCOMPARE(iq.chat().messages()[0].date(), QDateTime(QDate(1469, 7, 21), QTime(2, 56, 15), Qt::UTC));
QCOMPARE(iq.chat().messages()[1].isReceived(), false);
QCOMPARE(iq.chat().messages()[1].date(), QDateTime(QDate(1469, 7, 21), QTime(2, 56, 26), Qt::UTC));
QCOMPARE(iq.chat().messages()[1].body(), QLatin1String("Neither, fair saint, if either thee dislike."));
+ QCOMPARE(iq.chat().messages()[2].isReceived(), true);
+ QCOMPARE(iq.chat().messages()[2].date(), QDateTime(QDate(1469, 7, 21), QTime(2, 56, 33), Qt::UTC));
+ QCOMPARE(iq.chat().messages()[2].body(), QLatin1String("How cam'st thou hither, tell me, and wherefore?"));
serializePacket(iq, xml);
}