aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppPresence.cpp
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2018-12-30 15:19:28 +0100
committerJeremy Lainé <jeremy.laine@m4x.org>2019-01-04 10:07:36 +0100
commit4231f551d031bd82ce35fec63485882b31e2d1dc (patch)
treedee7aad679c4b1394996cac4116692eb90167590 /src/base/QXmppPresence.cpp
parent91f23c69dd39117e6b8253d89ebfaf27f7612b82 (diff)
downloadqxmpp-4231f551d031bd82ce35fec63485882b31e2d1dc.tar.gz
Implement XEP-0319: Last User Interaction in Presence
Diffstat (limited to 'src/base/QXmppPresence.cpp')
-rw-r--r--src/base/QXmppPresence.cpp53
1 files changed, 39 insertions, 14 deletions
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)