QXmpp: QXmppBlockingManager.h Source File

QXmpp Version: 1.14.4

Loading...
Searching...
No Matches
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
18 class 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
32 QXmppBlocklist();
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
44 class 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
55 QXmppBlockingManager();
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
QXmppBlockingManager::blocked
Q_SIGNAL void blocked(const QVector< QString > &jids)
QXmppBlockingManager::subscribedChanged
Q_SIGNAL void subscribedChanged()
QXmppBlockingManager::BlocklistResult
std::variant< QXmppBlocklist, QXmppError > BlocklistResult
Definition QXmppBlockingManager.h:52
QXmppBlockingManager::unblock
QXmppTask< Result > unblock(QString jid)
Definition QXmppBlockingManager.h:64
QXmppBlockingManager::block
QXmppTask< Result > block(QString jid)
Definition QXmppBlockingManager.h:62
QXmppBlockingManager::subscribed
bool subscribed
Whether the blocking manager is currently receiving updates of the blocklist.
Definition QXmppBlockingManager.h:49
QXmppBlockingManager::isSubscribed
bool isSubscribed() const
Returns whether the blocking manager currently receives updates of the blocklist.
Definition QXmppBlockingManager.cpp:194
QXmppBlockingManager::fetchBlocklist
QXmppTask< BlocklistResult > fetchBlocklist()
Fetches the list of blocked JIDs and subscribes to blocklist updates.
Definition QXmppBlockingManager.cpp:207
QXmppBlockingManager::unblocked
Q_SIGNAL void unblocked(const QVector< QString > &jids)
QXmppBlockingManager::Result
std::variant< QXmpp::Success, QXmppError > Result
Definition QXmppBlockingManager.h:53
QXmppBlocklist::containsEntry
bool containsEntry(QStringView) const
Definition QXmppBlockingManager.cpp:429
QXmppBlocklist::blockingState
BlockingState blockingState(const QString &jid) const
Definition QXmppBlockingManager.cpp:443
QXmppBlocklist::entries
QVector< QString > entries() const
Definition QXmppBlockingManager.cpp:417
QXmppBlocklist::BlockingState
std::variant< NotBlocked, PartiallyBlocked, Blocked > BlockingState
Definition QXmppBlockingManager.h:30
QXmppClientExtension::discoveryFeatures
virtual QStringList discoveryFeatures() const
Definition QXmppClientExtension.cpp:22
QXmppClientExtension::onUnregistered
virtual void onUnregistered(QXmppClient *client)
Definition QXmppClientExtension.cpp:95
QXmppClientExtension::onRegistered
virtual void onRegistered(QXmppClient *client)
Definition QXmppClientExtension.cpp:85
QXmppClientExtension::QXmppClientExtension
QXmppClientExtension()
Definition QXmppClientExtension.cpp:12
QXmppClientExtension::handleStanza
virtual bool handleStanza(const QDomElement &stanza)
You need to implement this method to process incoming XMPP stanzas.
Definition client/compat/removed_api.cpp:44
QXmppTask
Definition QXmppTask.h:46