diff options
| author | Melvin Keskin <melvo@olomono.de> | 2021-05-08 19:35:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-08 19:35:40 +0200 |
| commit | 826ece0480385c47c72f216e35e004b276d82498 (patch) | |
| tree | 0ebddddd5db2c32c567e256be1117c62a4978c49 | |
| parent | ab2ead62e9f5241cc28801d742698ba65d4c8bd5 (diff) | |
| download | qxmpp-826ece0480385c47c72f216e35e004b276d82498.tar.gz | |
RosterManager: Add subscription request signal with full presence (#346)
This makes it possible to get the statusText of subscription requests.
| -rw-r--r-- | src/client/QXmppRosterManager.cpp | 19 | ||||
| -rw-r--r-- | src/client/QXmppRosterManager.h | 3 | ||||
| -rw-r--r-- | tests/qxmpprostermanager/tst_qxmpprostermanager.cpp | 22 |
3 files changed, 44 insertions, 0 deletions
diff --git a/src/client/QXmppRosterManager.cpp b/src/client/QXmppRosterManager.cpp index 0f677929..10f98a15 100644 --- a/src/client/QXmppRosterManager.cpp +++ b/src/client/QXmppRosterManager.cpp @@ -4,6 +4,7 @@ * Authors: * Manjeet Dahiya * Jeremy Lainé + * Melvin Keskin * * Source: * https://github.com/qxmpp-project/qxmpp @@ -31,6 +32,23 @@ #include <QDomElement> +/// +/// \fn QXmppRosterManager::subscriptionRequestReceived +/// +/// This signal is emitted when a JID asks to subscribe to the user's presence. +/// +/// The user can either accept the request by calling acceptSubscription() or refuse it +/// by calling refuseSubscription(). +/// +/// \note If QXmppConfiguration::autoAcceptSubscriptions() is set to true, this +/// signal will not be emitted. +/// +/// \param subscriberBareJid bare JID that wants to subscribe to the user's presence +/// \param presence presence stanza containing the reason / message (presence.statusText()) +/// +/// \since QXmpp 1.5 +/// + class QXmppRosterManagerPrivate { public: @@ -234,6 +252,7 @@ void QXmppRosterManager::_q_presenceReceived(const QXmppPresence &presence) subscribe(bareJid); } else { emit subscriptionReceived(bareJid); + emit subscriptionRequestReceived(bareJid, presence); } break; default: diff --git a/src/client/QXmppRosterManager.h b/src/client/QXmppRosterManager.h index 2142a5f2..81f0538a 100644 --- a/src/client/QXmppRosterManager.h +++ b/src/client/QXmppRosterManager.h @@ -4,6 +4,7 @@ * Authors: * Manjeet Dahiya * Jeremy Lainé + * Melvin Keskin * * Source: * https://github.com/qxmpp-project/qxmpp @@ -119,6 +120,8 @@ Q_SIGNALS: /// signal will not be emitted. void subscriptionReceived(const QString &bareJid); + void subscriptionRequestReceived(const QString &subscriberBareJid, const QXmppPresence &presence); + /// This signal is emitted when the roster entry of a particular bareJid is /// added as a result of roster push. void itemAdded(const QString &bareJid); diff --git a/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp b/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp index 044567de..1cee09b1 100644 --- a/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp +++ b/tests/qxmpprostermanager/tst_qxmpprostermanager.cpp @@ -3,6 +3,7 @@ * * Authors: * Linus Jahn + * Melvin Keskin * * Source: * https://github.com/qxmpp-project/qxmpp @@ -36,6 +37,7 @@ private slots: void testDiscoFeatures(); void testRenameItem(); + void subscriptionRequestReceived(); private: QXmppClient client; @@ -105,5 +107,25 @@ void tst_QXmppRosterManager::testRenameItem() QVERIFY(requestSent); } +void tst_QXmppRosterManager::subscriptionRequestReceived() +{ + QXmppPresence presence; + presence.setType(QXmppPresence::Subscribe); + presence.setFrom(QStringLiteral("alice@example.org/notebook")); + presence.setStatusText(QStringLiteral("Hi, I'm Alice.")); + + bool subscriptionRequestReceived = false; + + connect(manager, &QXmppRosterManager::subscriptionRequestReceived, this, [&](const QString &subscriberBareJid, const QXmppPresence &presence) { + subscriptionRequestReceived = true; + + QCOMPARE(subscriberBareJid, QStringLiteral("alice@example.org")); + QCOMPARE(presence.statusText(), QStringLiteral("Hi, I'm Alice.")); + }); + + emit client.presenceReceived(presence); + QVERIFY(subscriptionRequestReceived); +} + QTEST_MAIN(tst_QXmppRosterManager) #include "tst_qxmpprostermanager.moc" |
