From efb4c011c1034008c12ed695d7da4a7d1cdb2968 Mon Sep 17 00:00:00 2001 From: Sergei Ilinykh Date: Fri, 21 Jun 2024 13:03:11 +0300 Subject: [PATCH] Make pubsub avatar public --- src/avatars.cpp | 5 +++-- src/pepmanager.cpp | 18 ++++++++++++------ src/pepmanager.h | 15 +++++---------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/avatars.cpp b/src/avatars.cpp index 7b6366ae3..3a6931fe5 100644 --- a/src/avatars.cpp +++ b/src/avatars.cpp @@ -986,7 +986,7 @@ void AvatarFactory::setSelfAvatar(const QImage &image) el.appendChild(doc->createTextNode(QString::fromLatin1(data.toBase64()))); d->selfAvatarData_ = data; d->selfAvatarHash_ = id; - account()->pepManager()->publish(PEP_AVATAR_DATA_NS, PubSubItem(id, el)); + account()->pepManager()->publish(PEP_AVATAR_DATA_NS, PubSubItem(id, el), PEPManager::Access::Open); } } @@ -1091,7 +1091,8 @@ void AvatarFactory::publish_success(const QString &n, const PubSubItem &item) info_el.setAttribute("width", avatar_image.width()); info_el.setAttribute("type", image2type(d->selfAvatarData_)); meta_el.appendChild(info_el); - account()->pepManager()->publish(PEP_AVATAR_METADATA_NS, PubSubItem(d->selfAvatarHash_, meta_el)); + account()->pepManager()->publish(PEP_AVATAR_METADATA_NS, PubSubItem(d->selfAvatarHash_, meta_el), + PEPManager::Access::Open); if (account()->client()->serverInfoManager()->accountFeatures().hasAvatarConversion()) { VCardFactory::instance()->setPhoto(account()->jid(), d->selfAvatarData_, VCardFactory::Silent); } diff --git a/src/pepmanager.cpp b/src/pepmanager.cpp index 1801f017e..5dc949abc 100644 --- a/src/pepmanager.cpp +++ b/src/pepmanager.cpp @@ -164,7 +164,7 @@ class PEPCreateNodeTask : public Task class PEPPublishTask : public Task { public: - PEPPublishTask(Task *parent, const QString &node, const PubSubItem &it, PEPManager::Access access, + PEPPublishTask(Task *parent, const QString &node, const PubSubItem &it, std::optional access, bool persisteItems = false) : Task(parent), node_(node), item_(it) { iq_ = createIQ(doc(), "set", "", id()); @@ -182,18 +182,24 @@ class PEPPublishTask : public Task { } publish.appendChild(item); - if (access != PEPManager::DefaultAccess || persisteItems) { + if (access || persisteItems) { QDomElement conf = doc()->createElement("publish-options"); XData form(XData::Data_Submit); form.setRegistrarType(QLatin1String("http://jabber.org/protocol/pubsub#publish-options")); XMPP::XData::FieldList fields; - if (access != PEPManager::DefaultAccess) { + if (access) { XMPP::XData::Field f; f.setVar(QLatin1String("pubsub#access_model")); - if (access == PEPManager::PublicAccess) { + if (*access == PEPManager::Access::Open) { f.setValue({ QLatin1String("open") }); - } else if (access == PEPManager::PresenceAccess) { + } else if (access == PEPManager::Access::Presence) { f.setValue({ QLatin1String("presence") }); + } else if (access == PEPManager::Access::Roster) { + f.setValue({ QLatin1String("roster") }); + } else if (access == PEPManager::Access::Authorize) { + f.setValue({ QLatin1String("authorize") }); + } else if (access == PEPManager::Access::Whitelist) { + f.setValue({ QLatin1String("whitelist") }); } fields << f; } @@ -463,7 +469,7 @@ void PEPManager::unsubscribeFinished() saveSubscriptions(); }*/ -Task *PEPManager::publish(const QString &node, const PubSubItem &it, Access access, bool persisteItems) +Task *PEPManager::publish(const QString &node, const PubSubItem &it, std::optional access, bool persisteItems) { // if (!canPublish(node)) // return; diff --git a/src/pepmanager.h b/src/pepmanager.h index c83cb71ab..c734f1357 100644 --- a/src/pepmanager.h +++ b/src/pepmanager.h @@ -22,6 +22,8 @@ #include "iris/xmpp_task.h" +#include + class PubSubSubscription; class QString; @@ -60,15 +62,7 @@ class PEPManager : public QObject { Q_OBJECT public: - enum Access { DefaultAccess, PresenceAccess, PublicAccess }; - - /* Implement all - * - - - - - */ + enum class Access { Open, Presence, Roster, Authorize, Whitelist }; PEPManager(XMPP::Client *client, ServerInfoManager *serverInfo); @@ -79,7 +73,8 @@ class PEPManager : public QObject { // void subscribe(const QString&, const QString&); // void unsubscribe(const QString&, const QString&); - XMPP::Task *publish(const QString &node, const PubSubItem &, Access = DefaultAccess, bool persisteItems = false); + XMPP::Task *publish(const QString &node, const PubSubItem &, std::optional = {}, + bool persisteItems = false); void retract(const QString &node, const QString &id); void disable(const QString &tagName, const QString &node, const QString &id); PEPGetTask *get(const Jid &jid, const QString &node, const QString &id);