From 4231f551d031bd82ce35fec63485882b31e2d1dc Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 30 Dec 2018 15:19:28 +0100 Subject: Implement XEP-0319: Last User Interaction in Presence --- src/base/QXmppPresence.cpp | 53 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 14 deletions(-) (limited to 'src/base/QXmppPresence.cpp') 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 +#include #include #include #include "QXmppConstants_p.h" @@ -76,6 +77,9 @@ public: QString mucPassword; QList 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) -- cgit v1.2.3