QXmpp: QXmppBlockingManager Class Reference

QXmpp Version: 1.14.3

Loading...
Searching...
No Matches
QXmppBlockingManager Class Reference
Managers

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

Inheritance diagram for QXmppBlockingManager:

## Public Types
using | BlocklistResult = std::variant<QXmppBlocklist, QXmppError>
using | Result = std::variant<QXmpp::Success, QXmppError>

## Public Member Functions
bool | isSubscribed () const
| Returns whether the blocking manager currently receives updates of the blocklist.
Q_SIGNAL void | subscribedChanged ()
QXmppTask< BlocklistResult > | fetchBlocklist ()
| Fetches the list of blocked JIDs and subscribes to blocklist updates.
QXmppTask< Result > | block (QString jid)
QXmppTask< Result > | block (QVector< QString > jids)
QXmppTask< Result > | unblock (QString jid)
QXmppTask< Result > | unblock (QVector< QString > jids)
Q_SIGNAL void | blocked (const QVector< QString > &jids)
Q_SIGNAL void | unblocked (const QVector< QString > &jids)
Public Member Functions inherited from QXmppClientExtension
| QXmppClientExtension ()
virtual QStringList | discoveryFeatures () const
virtual QList< QXmppDiscoIdentity > | discoveryIdentities () const
virtual bool | handleStanza (const QDomElement &stanza)
| You need to implement this method to process incoming XMPP stanzas.
virtual bool | handleStanza (const QDomElement &stanza, const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
| You need to implement this method to process incoming XMPP stanzas.
Public Member Functions inherited from QXmppLoggable
| QXmppLoggable (QObject *parent=nullptr)
Q_SIGNAL void | setGauge (const QString &gauge, double value)
| Sets the given gauge to value.
Q_SIGNAL void | logMessage (QXmppLogger::MessageType type, const QString &msg)
| This signal is emitted to send logging messages.
Q_SIGNAL void | updateCounter (const QString &counter, qint64 amount=1)
| Updates the given counter by amount.

## Properties
bool | subscribed
| Whether the blocking manager is currently receiving updates of the blocklist.

## Additional Inherited Members
Protected Member Functions inherited from QXmppClientExtension
QXmppClient * | client () const
virtual void | setClient (QXmppClient *client)
virtual void | onRegistered (QXmppClient *client)
virtual void | onUnregistered (QXmppClient *client)
void | injectIq (const QDomElement &element, const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
bool | injectMessage (QXmppMessage &&message)
Protected Member Functions inherited from QXmppLoggable
void | debug (const QString &message)
| Logs a debugging message.
void | info (const QString &message)
| Logs an informational message.
void | warning (const QString &message)
| Logs a warning message.
void | logReceived (const QString &message)
| Logs a received packet.
void | logSent (const QString &message)
| Logs a sent packet.

## Detailed Description

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

## 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;
}
});
QXmpp::hasValue
bool hasValue(const Result< T > &r)
Definition QXmppGlobal.h:216

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>();
QXmppClientExtension::client
QXmppClient * client() const
Definition QXmppClientExtension.cpp:57

See also
  QXmppBlocklist

Since
  QXmpp 1.6

## Member Typedef Documentation

## ◆ BlocklistResult

using QXmppBlockingManager::BlocklistResult = std::variant<QXmppBlocklist, QXmppError>

Contains a QXmppBlocklist or an error.

## ◆ Result

using QXmppBlockingManager::Result = std::variant<QXmpp::Success, QXmppError>

Contains QXmpp::Success or an error.

## Member Function Documentation

## ◆ block() [1/2]

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

Blocks a JID.

See also
  unblock()

## ◆ block() [2/2]

QXmppTask< QXmppBlockingManager::Result > QXmppBlockingManager::block | ( | QVector< QString > | jids | ) |

Blocks a list of JIDs.

See also
  unblock()

## ◆ blocked()

Q_SIGNAL void QXmppBlockingManager::blocked | ( | const QVector< QString > & | jids | ) |

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

This is also emitted when you call block().

## ◆ fetchBlocklist()

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.

## ◆ isSubscribed()

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().

## ◆ subscribedChanged()

Q_SIGNAL void QXmppBlockingManager::subscribedChanged | ( |  | ) |

Called whenever the state of the subscription to blocklist updates has changed.

## ◆ unblock() [1/2]

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

Unblocks a JID.

See also
  block()

## ◆ unblock() [2/2]

QXmppTask< QXmppBlockingManager::Result > QXmppBlockingManager::unblock | ( | QVector< QString > | jids | ) |

Unblocks a list of JIDs.

See also
  block()

## ◆ unblocked()

Q_SIGNAL void QXmppBlockingManager::unblocked | ( | const QVector< QString > & | jids | ) |

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

This is also emitted when you call unblock().

The documentation for this class was generated from the following files:

- QXmppBlockingManager.h
- QXmppBlockingManager.cpp