aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2012-07-17 11:33:24 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2012-07-17 11:33:24 +0200
commita128ad2833e1444e430270b4f312b5a698053a33 (patch)
tree6e66e533dac6e21b37749a153e5fc8b102980720
parentb1b30b840cb0930017fcb48bbfa73e746b707001 (diff)
downloadqxmpp-a128ad2833e1444e430270b4f312b5a698053a33.tar.gz
add result-set management to QXmppArchiveIq
-rw-r--r--src/base/QXmppArchiveIq.cpp20
-rw-r--r--src/base/QXmppArchiveIq.h10
-rw-r--r--src/client/QXmppArchiveManager.cpp2
-rw-r--r--src/client/QXmppArchiveManager.h2
-rw-r--r--tests/tests.cpp35
-rw-r--r--tests/tests.h1
6 files changed, 57 insertions, 13 deletions
diff --git a/src/base/QXmppArchiveIq.cpp b/src/base/QXmppArchiveIq.cpp
index 7de572de..8151ff9c 100644
--- a/src/base/QXmppArchiveIq.cpp
+++ b/src/base/QXmppArchiveIq.cpp
@@ -111,7 +111,7 @@ void QXmppArchiveChat::parse(const QDomElement &element)
}
}
-void QXmppArchiveChat::toXml(QXmlStreamWriter *writer) const
+void QXmppArchiveChat::toXml(QXmlStreamWriter *writer, const QXmppResultSetReply &rsm) const
{
writer->writeStartElement("chat");
writer->writeAttribute("xmlns", ns_archive);
@@ -133,6 +133,8 @@ void QXmppArchiveChat::toXml(QXmlStreamWriter *writer) const
writer->writeEndElement();
prevTime = message.date();
}
+ if (!rsm.isNull())
+ rsm.toXml(writer);
writer->writeEndElement();
}
@@ -234,6 +236,16 @@ void QXmppArchiveChatIq::setChat(const QXmppArchiveChat &chat)
m_chat = chat;
}
+QXmppResultSetReply QXmppArchiveChatIq::resultSetReply() const
+{
+ return m_rsmReply;
+}
+
+void QXmppArchiveChatIq::setResultSetReply(const QXmppResultSetReply& rsm)
+{
+ m_rsmReply = rsm;
+}
+
bool QXmppArchiveChatIq::isArchiveChatIq(const QDomElement &element)
{
QDomElement chatElement = element.firstChildElement("chat");
@@ -243,12 +255,14 @@ bool QXmppArchiveChatIq::isArchiveChatIq(const QDomElement &element)
void QXmppArchiveChatIq::parseElementFromChild(const QDomElement &element)
{
- m_chat.parse(element.firstChildElement("chat"));
+ QDomElement chatElement = element.firstChildElement("chat");
+ m_chat.parse(chatElement);
+ m_rsmReply.parse(chatElement);
}
void QXmppArchiveChatIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
- m_chat.toXml(writer);
+ m_chat.toXml(writer, m_rsmReply);
}
/// Constructs a QXmppArchiveListIq.
diff --git a/src/base/QXmppArchiveIq.h b/src/base/QXmppArchiveIq.h
index 9e22bf71..18dff7db 100644
--- a/src/base/QXmppArchiveIq.h
+++ b/src/base/QXmppArchiveIq.h
@@ -83,7 +83,7 @@ public:
/// \cond
void parse(const QDomElement &element);
- void toXml(QXmlStreamWriter *writer) const;
+ void toXml(QXmlStreamWriter *writer, const QXmppResultSetReply &rsm = QXmppResultSetReply()) const;
/// \endcond
private:
@@ -107,6 +107,9 @@ public:
QXmppArchiveChat chat() const;
void setChat(const QXmppArchiveChat &chat);
+ QXmppResultSetReply resultSetReply() const;
+ void setResultSetReply(const QXmppResultSetReply &rsm);
+
/// \cond
static bool isArchiveChatIq(const QDomElement &element);
/// \endcond
@@ -119,6 +122,7 @@ protected:
private:
QXmppArchiveChat m_chat;
+ QXmppResultSetReply m_rsmReply;
};
/// \brief Represents an archive list as defined by XEP-0136: Message Archiving.
@@ -217,9 +221,6 @@ public:
QXmppResultSetQuery resultSetQuery() const;
void setResultSetQuery(const QXmppResultSetQuery &rsm);
- QXmppResultSetReply resultSetReply() const;
- void setResultSetReply(const QXmppResultSetReply &rsm);
-
/// \cond
static bool isArchiveRetrieveIq(const QDomElement &element);
/// \endcond
@@ -234,7 +235,6 @@ private:
QString m_with;
QDateTime m_start;
QXmppResultSetQuery m_rsmQuery;
- QXmppResultSetReply m_rsmReply;
};
/// \brief Represents an archive preference IQ as defined by XEP-0136: Message Archiving.
diff --git a/src/client/QXmppArchiveManager.cpp b/src/client/QXmppArchiveManager.cpp
index 065e42c8..ff712f9a 100644
--- a/src/client/QXmppArchiveManager.cpp
+++ b/src/client/QXmppArchiveManager.cpp
@@ -37,7 +37,7 @@ bool QXmppArchiveManager::handleStanza(const QDomElement &element)
{
QXmppArchiveChatIq archiveIq;
archiveIq.parse(element);
- emit archiveChatReceived(archiveIq.chat());
+ emit archiveChatReceived(archiveIq.chat(), archiveIq.resultSetReply());
return true;
}
else if(QXmppArchiveListIq::isArchiveListIq(element))
diff --git a/src/client/QXmppArchiveManager.h b/src/client/QXmppArchiveManager.h
index 3ef2c3ee..04c34759 100644
--- a/src/client/QXmppArchiveManager.h
+++ b/src/client/QXmppArchiveManager.h
@@ -73,7 +73,7 @@ signals:
/// This signal is emitted when archive chat is received
/// after calling retrieveCollection()
- void archiveChatReceived(const QXmppArchiveChat&);
+ void archiveChatReceived(const QXmppArchiveChat&, const QXmppResultSetReply &rsm = QXmppResultSetReply());
};
#endif
diff --git a/tests/tests.cpp b/tests/tests.cpp
index 501ec184..9f7bbb16 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -229,9 +229,13 @@ void TestPackets::testArchiveList()
serializePacket(iq, xml);
}
-void TestPackets::testArchiveChat()
+void TestPackets::testArchiveChat_data()
{
- const QByteArray xml(
+ QTest::addColumn<QByteArray>("xml");
+ QTest::addColumn<int>("count");
+
+ QTest::newRow("no rsm") <<
+ QByteArray(
"<iq id=\"chat_1\" type=\"result\">"
"<chat xmlns=\"urn:xmpp:archive\""
" with=\"juliet@capulet.com\""
@@ -243,7 +247,31 @@ void TestPackets::testArchiveChat()
"<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>");
+ "</iq>") << -1;
+
+ QTest::newRow("with rsm") <<
+ QByteArray(
+ "<iq id=\"chat_1\" type=\"result\">"
+ "<chat xmlns=\"urn:xmpp:archive\""
+ " with=\"juliet@capulet.com\""
+ " start=\"1469-07-21T02:56:15Z\""
+ " subject=\"She speaks!\""
+ " version=\"4\""
+ ">"
+ "<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>"
+ "<set xmlns=\"http://jabber.org/protocol/rsm\">"
+ "<count>3</count>"
+ "</set>"
+ "</chat>"
+ "</iq>") << 3;
+}
+
+void TestPackets::testArchiveChat()
+{
+ QFETCH(QByteArray, xml);
+ QFETCH(int, count);
QXmppArchiveChatIq iq;
parsePacket(iq, xml);
@@ -260,6 +288,7 @@ void TestPackets::testArchiveChat()
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?"));
+ QCOMPARE(iq.resultSetReply().count(), count);
serializePacket(iq, xml);
}
diff --git a/tests/tests.h b/tests/tests.h
index c6d67b27..172c2bf6 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -45,6 +45,7 @@ class TestPackets : public QObject
private slots:
void testArchiveList_data();
void testArchiveList();
+ void testArchiveChat_data();
void testArchiveChat();
void testArchiveRemove();
void testArchiveRetrieve_data();