Skip to content

Commit

Permalink
Allow loading non-png avatar data pubsub nodes
Browse files Browse the repository at this point in the history
XEP-0084 says only png is allowed to be there. But people publish whatever they want.
So we still want to read whateer is published. e.g jpeg
  • Loading branch information
Ri0n committed Jun 13, 2024
1 parent 260a7cb commit f0d8e29
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/avatars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class AvatarCache : public FileCache {
} else if (n == PEP_AVATAR_METADATA_NS && item.payload().tagName() == QLatin1String(PEP_AVATAR_METADATA_TN)) {
auto info = item.payload().firstChildElement(QLatin1String("info"));
if (info.isNull()) {
#ifdef AVATAR_EDBUG
qDebug() << "removeIcon AvatarType " << jidFull << AvatarCache::AvatarType;
#endif
result = AvatarCache::instance()->removeIcon(AvatarCache::AvatarType, jidFull);
auto it = jid2hash.find(jid);
if (it != jid2hash.end()) {
Expand All @@ -201,7 +204,7 @@ class AvatarCache : public FileCache {
} else {
auto id = item.id().toLatin1();
if (id == "current") {
return; // probably was in previous versions of xep
return; // should we handle singletons? probably previous versions of the xep
}
QByteArray hash = QByteArray::fromHex(id);
if (hash.size() < 20) {
Expand All @@ -211,16 +214,20 @@ class AvatarCache : public FileCache {
return; // doesn't look like sha1 hash. just ignore it
}

auto supportedMime = QImageReader::supportedMimeTypes();
for (; !info.isNull(); info = info.nextSiblingElement(QLatin1String("info"))) {
if (info.attribute(QLatin1String("type")).toLower() != QLatin1String("image/png")) {
continue; // TODO add support for QImageReader::supportedMimeTypes() (requires usage of qnam)
if (!supportedMime.contains(info.attribute(QLatin1String("type")).toLower())) {
continue;
}
if (!info.attribute(QLatin1String("url")).isEmpty()) {
continue; // web avatars are not currently supported. TODO but their support is highly expected
}
if (info.attribute(QLatin1String("id")) != item.id()) {
continue; // that's something totally unexpected
}
#ifdef AVATAR_EDBUG
qDebug() << "appendUser AvatarType " << jidFull;
#endif
// found in-band png (by xep84 hash is for png) avatar. So we can make request
result = appendUser(hash, AvatarCache::AvatarType, jidFull);
if (result == AvatarCache::NoData) {
Expand Down

0 comments on commit f0d8e29

Please sign in to comment.