QXmpp Version: 1.10.0
Public Types | Public Member Functions | Properties | List of all members
QXmppBlockingManager Class Reference

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

Inheritance diagram for QXmppBlockingManager:
Inheritance graph
[legend]
Collaboration diagram for QXmppBlockingManager:
Collaboration graph
[legend]

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. More...
 
Q_SIGNAL void subscribedChanged ()
 
QXmppTask< BlocklistResultfetchBlocklist ()
 Fetches the list of blocked JIDs and subscribes to blocklist updates. More...
 
QXmppTask< Resultblock (QString jid)
 
QXmppTask< Resultblock (QVector< QString > jids)
 
QXmppTask< Resultunblock (QString jid)
 
QXmppTask< Resultunblock (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< QXmppDiscoveryIq::IdentitydiscoveryIdentities () const
 
virtual bool handleStanza (const QDomElement &stanza)
 You need to implement this method to process incoming XMPP stanzas. More...
 
virtual bool handleStanza (const QDomElement &stanza, const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
 You need to implement this method to process incoming XMPP stanzas. More...
 
- Public Member Functions inherited from QXmppLoggable
 QXmppLoggable (QObject *parent=nullptr)
 

Properties

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

Additional Inherited Members

- Signals inherited from QXmppLoggable
void setGauge (const QString &gauge, double value)
 Sets the given gauge to value.
 
void logMessage (QXmppLogger::MessageType type, const QString &msg)
 This signal is emitted to send logging messages.
 
void updateCounter (const QString &counter, qint64 amount=1)
 Updates the given counter by amount.
 
- Protected Member Functions inherited from QXmppClientExtension
QXmppClientclient () 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)
 
void info (const QString &message)
 
void warning (const QString &message)
 
void logReceived (const QString &message)
 
void logSent (const QString &message)
 

Detailed Description

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

Use Cases

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 (std::holds_alternative<QXmpp::Success>(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:

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>();
Uses XEP-0191: Blocking Command to manage blocked accounts and services.
Definition: QXmppBlockingManager.h:45
QXmppClient * client() const
Definition: QXmppClientExtension.cpp:57
T * addNewExtension(Args... args)
Definition: QXmppClient.h:117
See also
QXmppBlocklist
Since
QXmpp 1.6

Member Typedef Documentation

◆ BlocklistResult

Contains a QXmppBlocklist or an error.

◆ Result

Contains QXmpp::Success or an error.

Member Function Documentation

◆ block() [1/2]

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

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

QXmppBlockingManager::subscribedChanged ( )

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

◆ unblock() [1/2]

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

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: