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 /src/base | |
| parent | 91f23c69dd39117e6b8253d89ebfaf27f7612b82 (diff) | |
| download | qxmpp-4231f551d031bd82ce35fec63485882b31e2d1dc.tar.gz | |
Implement XEP-0319: Last User Interaction in Presence
Diffstat (limited to 'src/base')
| -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 |
4 files changed, 47 insertions, 14 deletions
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: |
