diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-07-19 15:37:35 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-07-19 15:37:35 +0000 |
| commit | feee6f9b114a68fc7ec3242d0aa52fd2c9e5a242 (patch) | |
| tree | 57104cadcbaac0250a24b6eb00719ee95945f6c8 /source | |
| parent | 7160a51dc90f36a8911f203134cf0a4cac231794 (diff) | |
| download | qxmpp-feee6f9b114a68fc7ec3242d0aa52fd2c9e5a242.tar.gz | |
add support for chat room invitations to QXmppMucManager
Diffstat (limited to 'source')
| -rw-r--r-- | source/QXmppMucManager.cpp | 60 | ||||
| -rw-r--r-- | source/QXmppMucManager.h | 8 |
2 files changed, 62 insertions, 6 deletions
diff --git a/source/QXmppMucManager.cpp b/source/QXmppMucManager.cpp index 753e3412..d63dbc86 100644 --- a/source/QXmppMucManager.cpp +++ b/source/QXmppMucManager.cpp @@ -32,15 +32,21 @@ QXmppMucManager::QXmppMucManager(QXmppStream* stream, QObject *parent) : QObject(parent), m_stream(stream) { - bool check = connect(stream, SIGNAL(mucAdminIqReceived(const QXmppMucAdminIq&)), - this, SLOT(mucAdminIqReceived(const QXmppMucAdminIq&))); + bool check = connect(stream, SIGNAL(messageReceived(QXmppMessage)), + this, SLOT(messageReceived(QXmppMessage))); + Q_ASSERT(check); + + check = connect(stream, SIGNAL(mucAdminIqReceived(QXmppMucAdminIq)), + this, SLOT(mucAdminIqReceived(QXmppMucAdminIq))); + Q_ASSERT(check); - check = connect(stream, SIGNAL(mucOwnerIqReceived(const QXmppMucOwnerIq&)), - this, SLOT(mucOwnerIqReceived(const QXmppMucOwnerIq&))); + check = connect(stream, SIGNAL(mucOwnerIqReceived(QXmppMucOwnerIq)), + this, SLOT(mucOwnerIqReceived(QXmppMucOwnerIq))); Q_ASSERT(check); - check = QObject::connect(m_stream, SIGNAL(presenceReceived(const QXmppPresence&)), - this, SLOT(presenceReceived(const QXmppPresence&))); + check = QObject::connect(m_stream, SIGNAL(presenceReceived(QXmppPresence)), + this, SLOT(presenceReceived(QXmppPresence))); + Q_ASSERT(check); } /// Joins the given chat room with the requested nickname. @@ -130,6 +136,30 @@ bool QXmppMucManager::setRoomConfiguration(const QString &roomJid, const QXmppDa return m_stream->sendPacket(iqPacket); } +/// Invite a user to a chat room. +/// +/// \param roomJid +/// \param jid +/// \param reason +/// +/// \return true if the message was sent, false otherwise +/// + +bool QXmppMucManager::sendInvitation(const QString &roomJid, const QString &jid, const QString &reason) +{ + QXmppElement x; + x.setTagName("x"); + x.setAttribute("xmlns", ns_conference); + x.setAttribute("jid", roomJid); + x.setAttribute("reason", reason); + + QXmppMessage message; + message.setTo(jid); + message.setType(QXmppMessage::Normal); + message.setExtensions(x); + return m_stream->sendPacket(message); +} + /// Send a message to a chat room. /// /// \param roomJid @@ -153,6 +183,24 @@ bool QXmppMucManager::sendMessage(const QString &roomJid, const QString &text) return m_stream->sendPacket(msg); } +void QXmppMucManager::messageReceived(const QXmppMessage &msg) +{ + if (msg.type() != QXmppMessage::Normal) + return; + + // process room invitations + foreach (const QXmppElement &extension, msg.extensions()) + { + if (extension.tagName() == "x" && extension.attribute("xmlns") == ns_conference) + { + const QString roomJid = extension.attribute("jid"); + if (!roomJid.isEmpty() && !m_nickNames.contains(roomJid)) + emit invitationReceived(roomJid, msg.from(), extension.attribute("reason")); + break; + } + } +} + void QXmppMucManager::mucAdminIqReceived(const QXmppMucAdminIq &iq) { Q_UNUSED(iq); diff --git a/source/QXmppMucManager.h b/source/QXmppMucManager.h index 396b757e..7e9568e3 100644 --- a/source/QXmppMucManager.h +++ b/source/QXmppMucManager.h @@ -30,6 +30,7 @@ #include "QXmppPresence.h" class QXmppDataForm; +class QXmppMessage; class QXmppMucAdminIq; class QXmppMucOwnerIq; class QXmppStream; @@ -52,15 +53,22 @@ public: bool requestRoomConfiguration(const QString &roomJid); bool setRoomConfiguration(const QString &roomJid, const QXmppDataForm &form); + bool sendInvitation(const QString &roomJid, const QString &jid, const QString &reason); bool sendMessage(const QString &roomJid, const QString &text); QMap<QString, QXmppPresence> roomParticipants(const QString& bareJid) const; signals: + /// This signal is emitted when an invitation to a chat room is received. + void invitationReceived(const QString &roomJid, const QString &inviter, const QString &reason); + + /// This signal is emitted when the configuration form for a chat room is received. void roomConfigurationReceived(const QString &roomJid, const QXmppDataForm &configuration); + void roomParticipantChanged(const QString &roomJid, const QString &nickName); private slots: + void messageReceived(const QXmppMessage &message); void mucAdminIqReceived(const QXmppMucAdminIq &iq); void mucOwnerIqReceived(const QXmppMucOwnerIq &iq); void presenceReceived(const QXmppPresence &presence); |
