Loading...
Searching...
No Matches
QXmppBlockingManager.h
// SPDX-FileCopyrightText: 2023 Linus Jahn <lnj@kaidan.im>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef QXMPPBLOCKINGMANAGER_H
#define QXMPPBLOCKINGMANAGER_H
#include "QXmppClientExtension.h"
#include "QXmppError.h"
#include "QXmppTask.h"
#include <variant>
#include <QVector>
struct QXmppBlockingManagerPrivate;
class QXMPP_EXPORT QXmppBlocklist
{
public:
struct NotBlocked { };
struct Blocked {
QVector<QString> blockingEntries;
QVector<QString> partiallyBlockingEntries;
};
struct PartiallyBlocked {
QVector<QString> partiallyBlockingEntries;
};
using BlockingState = std::variant<NotBlocked, PartiallyBlocked, Blocked>;
QXmppBlocklist();
QXmppBlocklist(QVector<QString> entries);
QXMPP_PRIVATE_DECLARE_RULE_OF_SIX(QXmppBlocklist)
QVector<QString> entries() const;
bool containsEntry(QStringView) const;
BlockingState blockingState(const QString &jid) const;
private:
QVector<QString> m_blocklist;
};
class QXMPP_EXPORT QXmppBlockingManager : public QXmppClientExtension
{
Q_OBJECT
Q_PROPERTY(bool subscribed READ isSubscribed NOTIFY subscribedChanged)
public:
using BlocklistResult = std::variant<QXmppBlocklist, QXmppError>;
using Result = std::variant<QXmpp::Success, QXmppError>;
QXmppBlockingManager();
~QXmppBlockingManager() override;
bool isSubscribed() const;
Q_SIGNAL void subscribedChanged();
QXmppTask<BlocklistResult> fetchBlocklist();
QXmppTask<Result> block(QString jid) { return block(QVector<QString> { std::move(jid) }); }
QXmppTask<Result> block(QVector<QString> jids);
QXmppTask<Result> unblock(QString jid) { return unblock(QVector<QString> { std::move(jid) }); }
QXmppTask<Result> unblock(QVector<QString> jids);
Q_SIGNAL void blocked(const QVector<QString> &jids);
Q_SIGNAL void unblocked(const QVector<QString> &jids);
QStringList discoveryFeatures() const override;
void onRegistered(QXmppClient *) override;
void onUnregistered(QXmppClient *) override;
bool handleStanza(const QDomElement &, const std::optional<QXmppE2eeMetadata> &) override;
private:
void onConnected();
std::unique_ptr<QXmppBlockingManagerPrivate> d;
};
#endif // QXMPPBLOCKINGMANAGER_H
QXmppBlockingManager
Uses XEP-0191: Blocking Command to manage blocked accounts and services.
Definition QXmppBlockingManager.h:45
QXmppBlockingManager::unblocked
Q_SIGNAL void unblocked(const QVector< QString > &jids)
QXmppBlockingManager::unblock
QXmppTask< Result > unblock(QString jid)
Definition QXmppBlockingManager.h:64
QXmppBlockingManager::BlocklistResult
std::variant< QXmppBlocklist, QXmppError > BlocklistResult
Definition QXmppBlockingManager.h:52
QXmppBlockingManager::subscribedChanged
Q_SIGNAL void subscribedChanged()
QXmppBlockingManager::blocked
Q_SIGNAL void blocked(const QVector< QString > &jids)
QXmppBlockingManager::block
QXmppTask< Result > block(QString jid)
Definition QXmppBlockingManager.h:62
QXmppBlockingManager::Result
std::variant< QXmpp::Success, QXmppError > Result
Definition QXmppBlockingManager.h:53
QXmppBlocklist
List of blocked entries according to XEP-0191: Blocking Command with helper functions to check the bl...
Definition QXmppBlockingManager.h:19
QXmppBlocklist::BlockingState
std::variant< NotBlocked, PartiallyBlocked, Blocked > BlockingState
Definition QXmppBlockingManager.h:30
QXmppClientExtension
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition QXmppClientExtension.h:32
QXmppClient
Main class for starting and managing connections to XMPP servers.
Definition QXmppClient.h:62
QXmppTask
Definition QXmppTask.h:62