QXmpp Version: 1.10.0
QXmppBlockingManager.h
1// SPDX-FileCopyrightText: 2023 Linus Jahn <lnj@kaidan.im>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef QXMPPBLOCKINGMANAGER_H
6#define QXMPPBLOCKINGMANAGER_H
7
8#include "QXmppClientExtension.h"
9#include "QXmppError.h"
10#include "QXmppTask.h"
11
12#include <variant>
13
14#include <QVector>
15
16struct QXmppBlockingManagerPrivate;
17
18class QXMPP_EXPORT QXmppBlocklist
19{
20public:
21 struct NotBlocked { };
22 struct Blocked {
23 QVector<QString> blockingEntries;
24 QVector<QString> partiallyBlockingEntries;
25 };
26 struct PartiallyBlocked {
27 QVector<QString> partiallyBlockingEntries;
28 };
29
30 using BlockingState = std::variant<NotBlocked, PartiallyBlocked, Blocked>;
31
33 QXmppBlocklist(QVector<QString> entries);
34 QXMPP_PRIVATE_DECLARE_RULE_OF_SIX(QXmppBlocklist)
35
36 QVector<QString> entries() const;
37 bool containsEntry(QStringView) const;
38 BlockingState blockingState(const QString &jid) const;
39
40private:
41 QVector<QString> m_blocklist;
42};
43
44class QXMPP_EXPORT QXmppBlockingManager : public QXmppClientExtension
45{
46 Q_OBJECT
47
49 Q_PROPERTY(bool subscribed READ isSubscribed NOTIFY subscribedChanged)
50
51public:
52 using BlocklistResult = std::variant<QXmppBlocklist, QXmppError>;
53 using Result = std::variant<QXmpp::Success, QXmppError>;
54
56 ~QXmppBlockingManager() override;
57
58 bool isSubscribed() const;
59 Q_SIGNAL void subscribedChanged();
60
61 QXmppTask<BlocklistResult> fetchBlocklist();
62 QXmppTask<Result> block(QString jid) { return block(QVector<QString> { std::move(jid) }); }
63 QXmppTask<Result> block(QVector<QString> jids);
64 QXmppTask<Result> unblock(QString jid) { return unblock(QVector<QString> { std::move(jid) }); }
65 QXmppTask<Result> unblock(QVector<QString> jids);
66
67 Q_SIGNAL void blocked(const QVector<QString> &jids);
68 Q_SIGNAL void unblocked(const QVector<QString> &jids);
69
71 QStringList discoveryFeatures() const override;
72 void onRegistered(QXmppClient *) override;
73 void onUnregistered(QXmppClient *) override;
74 bool handleStanza(const QDomElement &, const std::optional<QXmppE2eeMetadata> &) override;
76
77private:
78 void onConnected();
79
80 std::unique_ptr<QXmppBlockingManagerPrivate> d;
81};
82
83#endif // QXMPPBLOCKINGMANAGER_H
Uses XEP-0191: Blocking Command to manage blocked accounts and services.
Definition: QXmppBlockingManager.h:45
Q_SIGNAL void unblocked(const QVector< QString > &jids)
QXmppTask< Result > unblock(QString jid)
Definition: QXmppBlockingManager.h:64
std::variant< QXmppBlocklist, QXmppError > BlocklistResult
Definition: QXmppBlockingManager.h:52
Q_SIGNAL void subscribedChanged()
Q_SIGNAL void blocked(const QVector< QString > &jids)
QXmppTask< Result > block(QString jid)
Definition: QXmppBlockingManager.h:62
std::variant< QXmpp::Success, QXmppError > Result
Definition: QXmppBlockingManager.h:53
List of blocked entries according to XEP-0191: Blocking Command with helper functions to check the bl...
Definition: QXmppBlockingManager.h:19
std::variant< NotBlocked, PartiallyBlocked, Blocked > BlockingState
Definition: QXmppBlockingManager.h:30
The QXmppClientExtension class is the base class for QXmppClient extensions.
Definition: QXmppClientExtension.h:32
Main class for starting and managing connections to XMPP servers.
Definition: QXmppClient.h:62
Definition: QXmppTask.h:62