From 0ae287b2c624df43b3744f79911d11baa0699c68 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 3 Jul 2012 11:17:27 +0200 Subject: Fix time computation in QXmppArchiveIq MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In message archive, the secs attribute is the time ellapsed since the last message, not the time passed since the beginning of the collection. Quoting the XEP-0136 §4.6 The time in whole seconds of the message relative to the previous message in the collection (or, for the first message, relative to the start of the collection) SHOULD be specified with a 'secs' attribute. (This behaviour was changed in the revision 0.7 of the JEP-0136) Signed-off-by: Jeremy Lainé --- src/base/QXmppArchiveIq.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/base/QXmppArchiveIq.cpp') diff --git a/src/base/QXmppArchiveIq.cpp b/src/base/QXmppArchiveIq.cpp index a194f61f..5c4b6f44 100644 --- a/src/base/QXmppArchiveIq.cpp +++ b/src/base/QXmppArchiveIq.cpp @@ -94,6 +94,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()) { @@ -101,7 +103,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; } @@ -120,12 +123,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(); } -- cgit v1.2.3