QXmppBlockingManager Class
Uses XEP-0191: Blocking Command to manage blocked accounts and services. More...
| Header: | #include <QXmppBlockingManager> |
| Since: | QXmpp 1.6 |
| Inherits: | QXmppClientExtension |
- List of all members, including inherited members
- QXmppBlockingManager is part of Managers.
Public Types
Public Functions
| QXmppTask<QXmppBlockingManager::Result> | block(QString jid) |
| QXmppTask<QXmppBlockingManager::Result> | block(QVector<QString> jids) |
| QXmppTask<QXmppBlockingManager::BlocklistResult> | fetchBlocklist() |
| bool | isSubscribed() const |
| QXmppTask<QXmppBlockingManager::Result> | unblock(QString jid) |
| QXmppTask<QXmppBlockingManager::Result> | unblock(QVector<QString> jids) |
Signals
| void | blocked(const QVector<QString> &jids) |
| void | subscribedChanged() |
| void | unblocked(const QVector<QString> &jids) |
Detailed Description
Use Cases
- listing blocked devices, accounts and servers
- blocking and unblocking JIDs
- getting notified when a new JID has been blocked or unblocked
Listing blocked devices
You can receive a list of blocked JIDs by using fetchBlocklist(). ``` manager->fetchBlocklist().then(this, [](auto result) { if (auto *blocklist = std::get_if<QXmppBlocklist>(&result)) { qDebug() << "Blocked JIDs:" << blocklist->entries(); } else if (auto *err = std::get_if<QXmppError>(&result)) { qDebug() << "Error fetching blocklist:" << err->description; } }); ```
The server will send updates to us for the rest of the stream. You can listen to the updates by connecting to blocked() and unblocked().
Note: The manager caches the blocklist, so after the first time the task will finish instantly.
Blocking and Unblocking
You can use block() and unblock() for this purpose. ``` manager->block("baduser@spam.im").then(this, [](auto result) { if (QXmpp::hasValue(result)) { qDebug() << "Blocked baduser@spam.im!"; } else if (auto *err = std::get_if<QXmppError>(&result)) { qDebug() << "Error:" << err->description; } }); ``` unblock() works likewise.
Blocklist Subscription
You will automatically receive blocklist updates after you requested the blocklist. You can connect to the blocked() and unblocked() signals.
Format
It is important to notice that the blocked JIDs are not limited to accounts, allowed are the following formats:
user@domain/resourceuser@domaindomain/resourcedomain
It is not possible to block a domain without blocking a specific account though (or another combination).
Setup
The blocking manager is not enabled by default and needs to be registered with your QXmppClient. ``` auto *blockingManager = client->addNewExtension<QXmppBlockingManager>(); ```
See also QXmppBlocklist.
Member Type Documentation
[alias] QXmppBlockingManager::BlocklistResult
Contains a QXmppBlocklist or an error.
[alias] QXmppBlockingManager::Result
Contains QXmpp::Success or an error.
Member Function Documentation
QXmppTask<QXmppBlockingManager::Result> QXmppBlockingManager::block(QString jid)
Blocks the JID jid.
See also unblock().
QXmppTask<QXmppBlockingManager::Result> QXmppBlockingManager::block(QVector<QString> jids)
Blocks a list of JIDs.
See also unblock().
[signal] void QXmppBlockingManager::blocked(const QVector<QString> &jids)
Emitted when a blocklist update with new blocked JIDs jids has been received.
This is also emitted when you call block().
QXmppTask<QXmppBlockingManager::BlocklistResult> QXmppBlockingManager::fetchBlocklist()
Fetches the list of blocked JIDs and subscribes to blocklist updates.
The manager will cache the blocklist and keep track of updates for the rest of the session. Later calls of this function will report the cached result immediately. Even calling this function multiple times before the first request has finished, will not trigger more than one IQ request being sent.
bool QXmppBlockingManager::isSubscribed() const
Returns whether the blocking manager currently receives updates of the blocklist.
The subscription is enabled automatically after fetching the blocklist using fetchBlocklist().
Note: Getter function for property subscribed.
[signal] void QXmppBlockingManager::subscribedChanged()
Called whenever the state of the subscription to blocklist updates has changed.
Note: Notifier signal for property subscribed.
QXmppTask<QXmppBlockingManager::Result> QXmppBlockingManager::unblock(QString jid)
Unblocks the JID jid.
See also block().
QXmppTask<QXmppBlockingManager::Result> QXmppBlockingManager::unblock(QVector<QString> jids)
Unblocks a list of JIDs.
See also block().
[signal] void QXmppBlockingManager::unblocked(const QVector<QString> &jids)
Emitted when a blocklist update with new unblocked JIDs jids has been received.
This is also emitted when you call unblock().