Skip to content

Commit

Permalink
Make pubsub avatar public
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jun 21, 2024
1 parent d46d66f commit efb4c01
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/avatars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
18 changes: 12 additions & 6 deletions src/pepmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PEPManager::Access> access,
bool persisteItems = false) : Task(parent), node_(node), item_(it)
{
iq_ = createIQ(doc(), "set", "", id());
Expand All @@ -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;
}
Expand Down Expand Up @@ -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> access, bool persisteItems)
{
// if (!canPublish(node))
// return;
Expand Down
15 changes: 5 additions & 10 deletions src/pepmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "iris/xmpp_task.h"

#include <optional>

class PubSubSubscription;
class QString;

Expand Down Expand Up @@ -60,15 +62,7 @@ class PEPManager : public QObject {
Q_OBJECT

public:
enum Access { DefaultAccess, PresenceAccess, PublicAccess };

/* Implement all
* <option><value>authorize</value></option>
<option><value>open</value></option>
<option><value>presence</value></option>
<option><value>roster</value></option>
<option><value>whitelist</value></option>
*/
enum class Access { Open, Presence, Roster, Authorize, Whitelist };

PEPManager(XMPP::Client *client, ServerInfoManager *serverInfo);

Expand All @@ -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<Access> = {},
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);
Expand Down

0 comments on commit efb4c01

Please sign in to comment.