diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-02-06 20:21:36 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-02-06 20:21:36 +0000 |
| commit | 310e05a8b2c718a071a98b01516ec01e28d5df74 (patch) | |
| tree | 4032bb405348bcdb55db8dd12b6ef908fcab39d9 /src | |
| parent | d793ea8b18527009ddd47816afbf52ada6ae7736 (diff) | |
| download | qxmpp-310e05a8b2c718a071a98b01516ec01e28d5df74.tar.gz | |
add QXmppMessageReceiptManager class
Diffstat (limited to 'src')
| -rw-r--r-- | src/QXmppMessageReceiptManager.cpp | 106 | ||||
| -rw-r--r-- | src/QXmppMessageReceiptManager.h | 65 | ||||
| -rw-r--r-- | src/src.pro | 2 |
3 files changed, 173 insertions, 0 deletions
diff --git a/src/QXmppMessageReceiptManager.cpp b/src/QXmppMessageReceiptManager.cpp new file mode 100644 index 00000000..720ac970 --- /dev/null +++ b/src/QXmppMessageReceiptManager.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2008-2011 The QXmpp developers + * + * Author: + * Georg Rudoy + * Jeremy Lainé + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include "QXmppMessageReceiptManager.h" + +#include <QDomElement> + +#include "QXmppConstants.h" +#include "QXmppMessage.h" +#include "QXmppClient.h" + +/// Constructs a QXmppMessageReceiptManager to handle incoming and outgoing +/// message delivery receipts. + +QXmppMessageReceiptManager::QXmppMessageReceiptManager() + : QXmppClientExtension() + , m_autoReceipt(true) +{ +} + +bool QXmppMessageReceiptManager::autoReceipt() const +{ + return m_autoReceipt; +} + +void QXmppMessageReceiptManager::setAutoReceipt(bool autoReceipt) +{ + m_autoReceipt = autoReceipt; +} + +/** Sends a receipt for the specified message. + */ +void QXmppMessageReceiptManager::sendReceipt(const QString &jid, const QString &id) +{ + QXmppMessage msg; + msg.setTo(jid); + msg.setReceiptId(id); + client()->sendPacket(msg); +} + +QStringList QXmppMessageReceiptManager::discoveryFeatures() const +{ + return QStringList(ns_message_receipts); +} + +bool QXmppMessageReceiptManager::handleStanza(const QDomElement &stanza) +{ + if (stanza.tagName() != "message") + return false; + + // Case 1: incoming receipt + // This way we handle the receipt and cancel any further processing. + const QDomElement &received = stanza.firstChildElement("received"); + if (received.namespaceURI() == ns_message_receipts) + { + QString id = received.attribute("id"); + + // check if it's old-style XEP + if (id.isEmpty()) + id = stanza.attribute("id"); + + emit messageDelivered(stanza.attribute("from"), id); + return true; + } + + // Case 2: incoming message requesting receipt + // If autoreceipt is enabled, we queue sending back receipt, otherwise + // we just ignore the message. In either case, we don't cancel any + // further processing. + if (m_autoReceipt && stanza.firstChildElement("request").namespaceURI() == ns_message_receipts) + { + const QString &jid = stanza.attribute("from"); + const QString &id = stanza.attribute("id"); + + // Send out receipt only if jid and id is not empty, otherwise fail + // silently. + if (!jid.isEmpty() && !id.isEmpty()) + QMetaObject::invokeMethod(this, + "sendReceipt", + Q_ARG(QString, jid), + Q_ARG(QString, id)); + } + + return false; +} diff --git a/src/QXmppMessageReceiptManager.h b/src/QXmppMessageReceiptManager.h new file mode 100644 index 00000000..8240eaaa --- /dev/null +++ b/src/QXmppMessageReceiptManager.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2008-2011 The QXmpp developers + * + * Authors: + * Georg Rudoy + * Jeremy Lainé + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#ifndef QXMPPMESSAGERECEIPTMANAGER_H +#define QXMPPMESSAGERECEIPTMANAGER_H + +#include "QXmppClientExtension.h" + +/// \brief The QXmppMessageReceiptManager class makes it possible to +/// send and receive message delivery receipts as defined in +/// XEP-0184: Message Delivery Receipts. +/// +/// \ingroup Managers + +class QXmppMessageReceiptManager : public QXmppClientExtension +{ + Q_OBJECT +public: + QXmppMessageReceiptManager(); + + bool autoReceipt() const; + void setAutoReceipt(bool); + + /// \cond + virtual QStringList discoveryFeatures() const; + virtual bool handleStanza(const QDomElement &stanza); + /// \endcond + +public slots: + void sendReceipt(const QString &jid, const QString &id); + +signals: + /// This signal is emitted when receipt for the message with the + /// given id is received. The id could be previously obtained by + /// calling QXmppMessage::id(). + + void messageDelivered(const QString &jid, const QString &id); + +private: + bool m_autoReceipt; + +}; + +#endif // QXMPPMESSAGERECEIPTMANAGER_H diff --git a/src/src.pro b/src/src.pro index d8ee76bb..d95763e2 100644 --- a/src/src.pro +++ b/src/src.pro @@ -53,6 +53,7 @@ INSTALL_HEADERS = QXmppUtils.h \ QXmppJingleIq.h \ QXmppLogger.h \ QXmppMessage.h \ + QXmppMessageReceiptManager.h \ QXmppMucIq.h \ QXmppMucManager.h \ QXmppNonSASLAuth.h \ @@ -117,6 +118,7 @@ SOURCES += QXmppUtils.cpp \ QXmppJingleIq.cpp \ QXmppLogger.cpp \ QXmppMessage.cpp \ + QXmppMessageReceiptManager.cpp \ QXmppMucIq.cpp \ QXmppMucManager.cpp \ QXmppNonSASLAuth.cpp \ |
