diff --git a/iris b/iris index 40c0d7e93..64e9997aa 160000 --- a/iris +++ b/iris @@ -1 +1 @@ -Subproject commit 40c0d7e93545a945134fec11711301e5608261fb +Subproject commit 64e9997aa1e9ffebc88bbddf01554e7f69e33b16 diff --git a/src/avatars.cpp b/src/avatars.cpp index 63146e2cb..3a55a55fd 100644 --- a/src/avatars.cpp +++ b/src/avatars.cpp @@ -40,6 +40,7 @@ #include "pixmaputil.h" #include "psiaccount.h" #include "vcardfactory.h" +#include "xmpp/xmpp-im/xmpp_serverinfomanager.h" #include #include @@ -1064,7 +1065,15 @@ void AvatarFactory::publish_success(const QString &n, const PubSubItem &item) info_el.setAttribute("type", image2type(d->selfAvatarData_)); meta_el.appendChild(info_el); account()->pepManager()->publish(PEP_AVATAR_METADATA_NS, PubSubItem(d->selfAvatarHash_, meta_el)); + if (account()->client()->serverInfoManager()->account_features().hasAvatarConversion()) { + VCardFactory::instance()->setPhoto(account()->jid(), d->selfAvatarData_, {}); + } d->selfAvatarData_.clear(); // we don't need it anymore + } else if (n == PEP_AVATAR_METADATA_NS) { + bool removed = item.payload().firstChildElement("metadata").firstChildElement("info").isNull(); + if (account()->client()->serverInfoManager()->account_features().hasAvatarConversion() && removed) { + VCardFactory::instance()->deletePhoto(account()->jid(), {}); + } } } diff --git a/src/psiaccount.cpp b/src/psiaccount.cpp index a6373eadf..7d258e344 100644 --- a/src/psiaccount.cpp +++ b/src/psiaccount.cpp @@ -2374,7 +2374,7 @@ void PsiAccount::serverFeaturesChanged() j->go(true); } - if (d->client->serverInfoManager()->features().hasVCard() && !d->vcardChecked) { + if (d->client->serverInfoManager()->server_features().hasVCard() && !d->vcardChecked) { // Get the vcard const VCard vcard = VCardFactory::instance()->vcard(d->jid); if (PsiOptions::instance()->getOption("options.vcard.query-own-vcard-on-login").toBool() || vcard.isEmpty() diff --git a/src/vcardfactory.cpp b/src/vcardfactory.cpp index e3ea9ca57..3f91d2212 100644 --- a/src/vcardfactory.cpp +++ b/src/vcardfactory.cpp @@ -235,6 +235,40 @@ VCardRequest *VCardFactory::getVCard(PsiAccount *account, const Jid &jid, Flags return queuedLoader_->enqueue(account, jid, flags, QueuedLoader::HighPriority); } +void VCardFactory::setPhoto(const Jid &j, const QByteArray &photo, Flags flags) +{ + VCard vc; + Jid sj; + if (flags & MucUser) { + sj = j; + vc = mucVcard(j); + } else { + sj = j.withResource({}); + vc = vcard(sj); + } + if (vc && vc.photo() != photo) { + vc.setPhoto({}); + saveVCard(sj, vc, flags); + } +} + +void VCardFactory::deletePhoto(const Jid &j, Flags flags) +{ + VCard vc; + Jid sj; + if (flags & MucUser) { + sj = j; + vc = mucVcard(j); + } else { + sj = j.withResource({}); + vc = vcard(sj); + } + if (vc && !vc.photo().isEmpty()) { + vc.setPhoto({}); + saveVCard(sj, vc, flags); + } +} + void VCardFactory::ensureVCardPhotoUpdated(PsiAccount *acc, const Jid &jid, Flags flags, const QByteArray &newPhotoHash) { VCard vc; diff --git a/src/vcardfactory.h b/src/vcardfactory.h index 51d96ccd2..0a4a73e86 100644 --- a/src/vcardfactory.h +++ b/src/vcardfactory.h @@ -58,6 +58,9 @@ class VCardFactory : public QObject { JT_VCard *setVCard(const PsiAccount *account, const VCard &v, const Jid &targetJid, VCardFactory::Flags flags); VCardRequest *getVCard(PsiAccount *account, const Jid &, VCardFactory::Flags flags = {}); + void setPhoto(const Jid &j, const QByteArray &photo, Flags flags); + void deletePhoto(const Jid &j, Flags flags); + // 1. check if it's needed to do a request, // 2. enqueue request if necessary (no vcard, or if hash doesn't match) // 3. vcardChanged() will be sent as usually when vcard is updated