diff options
| author | Linus Jahn <lnj@kaidan.im> | 2018-12-30 15:19:28 +0100 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2019-01-04 10:07:36 +0100 |
| commit | 4231f551d031bd82ce35fec63485882b31e2d1dc (patch) | |
| tree | dee7aad679c4b1394996cac4116692eb90167590 | |
| parent | 91f23c69dd39117e6b8253d89ebfaf27f7612b82 (diff) | |
| download | qxmpp-4231f551d031bd82ce35fec63485882b31e2d1dc.tar.gz | |
Implement XEP-0319: Last User Interaction in Presence
| -rw-r--r-- | doc/xep.doc | 1 | ||||
| -rw-r--r-- | src/base/QXmppConstants.cpp | 2 | ||||
| -rw-r--r-- | src/base/QXmppConstants_p.h | 2 | ||||
| -rw-r--r-- | src/base/QXmppPresence.cpp | 53 | ||||
| -rw-r--r-- | src/base/QXmppPresence.h | 4 | ||||
| -rw-r--r-- | tests/qxmpppresence/tst_qxmpppresence.cpp | 23 |
6 files changed, 71 insertions, 14 deletions
diff --git a/doc/xep.doc b/doc/xep.doc index 94e02f60..1a5bd147 100644 --- a/doc/xep.doc +++ b/doc/xep.doc @@ -39,6 +39,7 @@ Complete: - XEP-0280: Message Carbons - XEP-0308: Last Message Correction - XEP-0313: Message Archive Management +- XEP-0319: Last User Interaction in Presence - XEP-0352: Client State Indication Ongoing: diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp index 3254dd61..4621797f 100644 --- a/src/base/QXmppConstants.cpp +++ b/src/base/QXmppConstants.cpp @@ -126,6 +126,8 @@ const char* ns_forwarding = "urn:xmpp:forward:0"; const char* ns_message_correct = "urn:xmpp:message-correct:0"; // XEP-0313: Message Archive Management const char* ns_mam = "urn:xmpp:mam:1"; +// XEP-0319: Last User Interaction in Presence +const char* ns_idle = "urn:xmpp:idle:1"; // XEP-0333: Chat Markers const char* ns_chat_markers = "urn:xmpp:chat-markers:0"; // XEP-0352: Client State Indication diff --git a/src/base/QXmppConstants_p.h b/src/base/QXmppConstants_p.h index 17495b33..5ffb33ad 100644 --- a/src/base/QXmppConstants_p.h +++ b/src/base/QXmppConstants_p.h @@ -138,6 +138,8 @@ extern const char* ns_forwarding; extern const char* ns_message_correct; // XEP-0313: Message Archive Management extern const char* ns_mam; +// XEP-0319: Last User Interaction in Presence +extern const char* ns_idle; // XEP-0333: Char Markers extern const char* ns_chat_markers; // XEP-0352: Client State Indication diff --git a/src/base/QXmppPresence.cpp b/src/base/QXmppPresence.cpp index 259a2ea5..d52810f9 100644 --- a/src/base/QXmppPresence.cpp +++ b/src/base/QXmppPresence.cpp @@ -25,6 +25,7 @@ #include "QXmppPresence.h" #include "QXmppUtils.h" #include <QtDebug> +#include <QDateTime> #include <QDomElement> #include <QXmlStreamWriter> #include "QXmppConstants_p.h" @@ -76,6 +77,9 @@ public: QString mucPassword; QList<int> mucStatusCodes; bool mucSupported; + + // XEP-0319: Last User Interaction in Presence + QDateTime lastUserInteraction; }; /// Constructs a QXmppPresence. @@ -253,22 +257,17 @@ void QXmppPresence::parse(const QDomElement &element) d->capabilityHash = xElement.attribute("hash"); d->capabilityExt = xElement.attribute("ext").split(" ", QString::SkipEmptyParts); } - else if (xElement.tagName() == "addresses") - { - } - else if (xElement.tagName() == "error") - { - } - else if (xElement.tagName() == "show") - { - } - else if (xElement.tagName() == "status") - { - } - else if (xElement.tagName() == "priority") + // XEP-0319: Last User Interaction in Presence + else if (xElement.tagName() == "idle" && xElement.namespaceURI() == ns_idle) { + if (xElement.hasAttribute("since")) { + const QString since = xElement.attribute("since"); + d->lastUserInteraction = QXmppUtils::datetimeFromString(since); + } } - else + else if (xElement.tagName() != "addresses" && xElement.tagName() != "error" + && xElement.tagName() != "show" && xElement.tagName() != "status" + && xElement.tagName() != "priority") { // other extensions extensions << QXmppElement(xElement); @@ -352,6 +351,16 @@ void QXmppPresence::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } + // XEP-0319: Last User Interaction in Presence + if (!d->lastUserInteraction.isNull() && d->lastUserInteraction.isValid()) + { + xmlWriter->writeStartElement("idle"); + xmlWriter->writeAttribute("xmlns", ns_idle); + helperToXmlAddAttribute(xmlWriter, "since", QXmppUtils::datetimeToString( + d->lastUserInteraction)); + xmlWriter->writeEndElement(); + } + // other extensions QXmppStanza::extensionsToXml(xmlWriter); @@ -497,6 +506,22 @@ void QXmppPresence::setMucSupported(bool supported) d->mucSupported = supported; } +/// Returns when the last user interaction with the client took place. See +/// XEP-0319: Last User Interaction in Presence for details. + +QDateTime QXmppPresence::lastUserInteraction() const +{ + return d->lastUserInteraction; +} + +/// Sets the time of the last user interaction as defined in XEP-0319: Last +/// User Interaction in Presence. + +void QXmppPresence::setLastUserInteraction(const QDateTime& lastUserInteraction) +{ + d->lastUserInteraction = lastUserInteraction; +} + /// Indicates if the QXmppStanza is a stanza in the XMPP sence (i. e. a message, /// iq or presence) diff --git a/src/base/QXmppPresence.h b/src/base/QXmppPresence.h index f94c7c2a..f252e885 100644 --- a/src/base/QXmppPresence.h +++ b/src/base/QXmppPresence.h @@ -128,6 +128,10 @@ public: QStringList capabilityExt() const; + // XEP-0319: Last User Interaction in Presence + QDateTime lastUserInteraction() const; + void setLastUserInteraction(const QDateTime&); + bool isXmppStanza() const; private: diff --git a/tests/qxmpppresence/tst_qxmpppresence.cpp b/tests/qxmpppresence/tst_qxmpppresence.cpp index 5283f8ed..69908cd7 100644 --- a/tests/qxmpppresence/tst_qxmpppresence.cpp +++ b/tests/qxmpppresence/tst_qxmpppresence.cpp @@ -22,6 +22,7 @@ * */ +#include <QDateTime> #include <QObject> #include "QXmppPresence.h" @@ -40,6 +41,7 @@ private slots: void testPresenceWithMucItem(); void testPresenceWithMucPassword(); void testPresenceWithMucSupport(); + void testPresenceWithLastUserInteraction(); }; void tst_QXmppPresence::testPresence_data() @@ -231,5 +233,26 @@ void tst_QXmppPresence::testPresenceWithMucSupport() serializePacket(presence, xml); } +void tst_QXmppPresence::testPresenceWithLastUserInteraction() +{ + const QByteArray xml( + "<presence to=\"coven@chat.shakespeare.lit/thirdwitch\" " + "from=\"hag66@shakespeare.lit/pda\">" + "<idle xmlns=\"urn:xmpp:idle:1\" since=\"1969-07-21T02:56:15Z\"/>" + "</presence>"); + + QXmppPresence presence; + parsePacket(presence, xml); + QVERIFY(!presence.lastUserInteraction().isNull()); + QVERIFY(presence.lastUserInteraction().isValid()); + QCOMPARE(presence.lastUserInteraction(), QDateTime(QDate(1969, 7, 21), + QTime(2, 56, 15), Qt::UTC)); + serializePacket(presence, xml); + + QDateTime another(QDate(2025, 2, 5), QTime(15, 32, 8), Qt::UTC); + presence.setLastUserInteraction(another); + QCOMPARE(presence.lastUserInteraction(), another); +} + QTEST_MAIN(tst_QXmppPresence) #include "tst_qxmpppresence.moc" |
