QXmppBlockingManager Class

Uses XEP-0191: Blocking Command to manage blocked accounts and services. More...

Header: #include <QXmppBlockingManager.h>
Since: QXmpp 1.6
Inherits: QXmppClientExtension

Public Types

Properties

Public Functions

QXmppTask<QXmppBlockingManager::Result> block(QList<QString> jids)
QXmppTask<QXmppBlockingManager::Result> block(QString jid)
QXmppTask<QXmppBlockingManager::BlocklistResult> fetchBlocklist()
bool isSubscribed() const
(since QXmpp 1.17) QXmppTask<QXmppBlockingManager::Result> reportAndBlock(QString jid, QXmppSpamReport report)
QXmppTask<QXmppBlockingManager::Result> unblock(QList<QString> jids)
QXmppTask<QXmppBlockingManager::Result> unblock(QString jid)

Signals

void blocked(const QList<QString> &jids)
void subscribedChanged()
void unblocked(const QList<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.

Note: This will also trigger blocked() or unblocked() if you are subscribed to the blocklist.

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/resource
  • user@domain
  • domain/resource
  • domain

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.

Property Documentation

[read-only] subscribed : bool

Whether the blocking manager is currently receiving updates of the blocklist.

Access functions:

bool isSubscribed() const

Notifier signal:

Member Function Documentation

QXmppTask<QXmppBlockingManager::Result> QXmppBlockingManager::block(QList<QString> jids)

Blocks a list of JIDs.

See also unblock().

QXmppTask<QXmppBlockingManager::Result> QXmppBlockingManager::block(QString jid)

Blocks the JID jid.

See also unblock().

[signal] void QXmppBlockingManager::blocked(const QList<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.

[since QXmpp 1.17] QXmppTask<QXmppBlockingManager::Result> QXmppBlockingManager::reportAndBlock(QString jid, QXmppSpamReport report)

Blocks the JID jid and attaches a XEP-0377: Blocking Command Reports report.

The JID is blocked just like with block(); the report is only processed if the server advertises the urn:xmpp:reporting:1 feature in its service discovery information. Otherwise the JID is still blocked, but the report is silently ignored.

This function was introduced in QXmpp 1.17.

See also block() and QXmppSpamReport.

[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(QList<QString> jids)

Unblocks a list of JIDs.

See also block().

QXmppTask<QXmppBlockingManager::Result> QXmppBlockingManager::unblock(QString jid)

Unblocks the JID jid.

See also block().

[signal] void QXmppBlockingManager::unblocked(const QList<QString> &jids)

Emitted when a blocklist update with new unblocked JIDs jids has been received.

This is also emitted when you call unblock().