aboutsummaryrefslogtreecommitdiff
path: root/source/QXmppMessage.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-02-18 14:35:48 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-02-18 14:35:48 +0000
commitc5a44ae2523a298737d3ba8be0b32318a03d7260 (patch)
treee6be40f0a9d053a1edd3f859574897cf191f84e5 /source/QXmppMessage.cpp
parent87b7c17bb63e55109e3c0b67dd5dd97803562897 (diff)
downloadqxmpp-c5a44ae2523a298737d3ba8be0b32318a03d7260.tar.gz
add support for XEP-0085 : Chat State Notifications
Diffstat (limited to 'source/QXmppMessage.cpp')
-rw-r--r--source/QXmppMessage.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/source/QXmppMessage.cpp b/source/QXmppMessage.cpp
index cd8c905c..78fc75d4 100644
--- a/source/QXmppMessage.cpp
+++ b/source/QXmppMessage.cpp
@@ -22,14 +22,24 @@
*/
+#include "QXmppConstants.h"
#include "QXmppMessage.h"
#include "QXmppUtils.h"
#include <QDomElement>
#include <QXmlStreamWriter>
+static const char* chat_states[] = {
+ "",
+ "active",
+ "inactive",
+ "gone",
+ "composing",
+ "paused",
+};
+
QXmppMessage::QXmppMessage(const QString& from, const QString& to, const
QString& body, const QString& thread)
- : QXmppStanza(from, to), m_type(Chat), m_body(body), m_thread(thread)
+ : QXmppStanza(from, to), m_type(Chat), m_state(None), m_body(body), m_thread(thread)
{
}
@@ -109,6 +119,16 @@ void QXmppMessage::setTypeFromStr(const QString& str)
}
}
+QXmppMessage::State QXmppMessage::getState() const
+{
+ return m_state;
+}
+
+void QXmppMessage::setState(QXmppMessage::State state)
+{
+ m_state = state;
+}
+
void QXmppMessage::parse(QDomElement &element)
{
setFrom(element.attribute("from"));
@@ -128,6 +148,17 @@ void QXmppMessage::parse(QDomElement &element)
setError(error);
}
+ for (int i = Active; i <= Paused; i++)
+ {
+ QDomElement stateElement = element.firstChildElement(chat_states[i]);
+ if (!stateElement.isNull() &&
+ stateElement.namespaceURI() == ns_chat_states)
+ {
+ m_state = static_cast<QXmppMessage::State>(i);
+ break;
+ }
+ }
+
QDomElement xElement = element.firstChildElement("x");
if(!xElement.isNull())
setExtension(QXmppElement(xElement));
@@ -148,6 +179,14 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
if (!getThread().isEmpty())
helperToXmlAddTextElement(xmlWriter,"thread", getThread());
getError().toXml(xmlWriter);
+
+ if (m_state > None && m_state <= Paused)
+ {
+ xmlWriter->writeStartElement(chat_states[m_state]);
+ helperToXmlAddAttribute(xmlWriter, "xmlns", ns_chat_states);
+ xmlWriter->writeEndElement();
+ }
+
getExtension().toXml(xmlWriter);
xmlWriter->writeEndElement();
}