5#include <QXmppPubSubEvent.h>
6#include <QXmppPubSubManager.h>
8#include "StringLiterals.h"
10namespace QXmpp::Private::Pep {
13using GetResult = std::variant<T, QXmppError>;
14using PublishResult = std::variant<QString, QXmppError>;
16template<
typename ItemT>
19 auto result =
co_await pubSub->
requestItems<ItemT>(jid, nodeName);
22 if (!
getValue(result).items.isEmpty()) {
23 co_return getValue(result).items.constFirst();
25 co_return QXmppError { u
"User has no published items."_s, {} };
27 co_return getError(std::move(result));
33template<
typename ItemT,
typename NodeName,
typename Manager,
typename ReceivedSignal>
34inline bool handlePubSubEvent(
const QDomElement &element,
const QString &pubSubService,
const QString &eventNode, NodeName nodeName,
Manager *manager, ReceivedSignal itemReceived)
40 if (event.
eventType() == QXmppPubSubEventBase::Items) {
41 if (!event.
items().isEmpty()) {
42 (manager->*itemReceived)(pubSubService, event.
items().constFirst());
44 (manager->*itemReceived)(pubSubService, {});
47 }
else if (event.
eventType() == QXmppPubSubEventBase::Retract) {
48 (manager->*itemReceived)(pubSubService, {});
virtual void parse(const QDomElement &)=0
Definition QXmppOmemoManager.h:69
EventType eventType() const
Definition QXmppPubSubEvent.cpp:109
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:209
Definition QXmppTask.h:330
const T & getValue(const Result< T > &r)
Definition QXmppGlobal.h:232
bool hasValue(const Result< T > &r)
Definition QXmppGlobal.h:216
const QXmppError & getError(const Result< T > &r)
Definition QXmppError.h:68
Definition QXmppError.h:17