5#include <QXmppPubSubEvent.h>
6#include <QXmppPubSubManager.h>
8namespace QXmpp::Private::Pep {
11using GetResult = std::variant<T, QXmppError>;
12using PublishResult = std::variant<QString, QXmppError>;
14template<
typename ItemT>
19 auto process = [](PubSub::ItemsResult<ItemT> &&result) -> GetResult<ItemT> {
20 if (
const auto itemsResult = std::get_if<PubSub::Items<ItemT>>(&result)) {
21 if (!itemsResult->items.isEmpty()) {
22 return itemsResult->items.takeFirst();
24 return QXmppError { QStringLiteral(
"User has no published items."), {} };
26 return std::get<QXmppError>(std::move(result));
29 return chain<GetResult<ItemT>>(pubSub->
requestItems<ItemT>(jid, nodeName), parent, process);
34template<
typename ItemT,
typename NodeName,
typename Manager,
typename ReceivedSignal>
35inline bool handlePubSubEvent(
const QDomElement &element,
const QString &pubSubService,
const QString &eventNode, NodeName nodeName,
Manager *manager, ReceivedSignal itemReceived)
41 if (event.
eventType() == QXmppPubSubEventBase::Items) {
42 if (!event.
items().isEmpty()) {
43 (manager->*itemReceived)(pubSubService, event.
items().constFirst());
45 (manager->*itemReceived)(pubSubService, {});
48 }
else if (event.
eventType() == QXmppPubSubEventBase::Retract) {
49 (manager->*itemReceived)(pubSubService, {});
virtual void parse(const QDomElement &)=0
Definition: QXmppOmemoManager.h:69
EventType eventType() const
Definition: QXmppPubSubEvent.cpp:104
The QXmppPubSubEvent class represents a PubSub event notification as defined by XEP-0060: Publish-Sub...
Definition: QXmppPubSubEvent.h:78
QVector< T > items() const
Definition: QXmppPubSubEvent.h:99
The QXmppPubSubManager aims to provide publish-subscribe functionality as specified in XEP-0060: Publ...
Definition: QXmppPubSubManager.h:21
QXmppTask< ItemsResult< T > > requestItems(const QString &jid, const QString &nodeName)
Definition: QXmppPubSubManager.h:210
Definition: QXmppTask.h:62
Definition: QXmppError.h:17