diff --git a/src/avatars.cpp b/src/avatars.cpp index a532de721..9401e55ad 100644 --- a/src/avatars.cpp +++ b/src/avatars.cpp @@ -176,20 +176,20 @@ class AvatarCache : public FileCache { qWarning("avatars.cpp: Unexpected item payload"); } } else if (n == PEP_AVATAR_METADATA_NS) { - auto id = item.id().toLatin1(); - if (id == "current") { - return; // probably was in previous versions of xep - } - QByteArray hash = QByteArray::fromHex(id); - if (hash.size() < 20) { - // qDebug() << "not sha1"; - return; // doesn't look like sha1 hash. just ignore it - } - if (item.payload().tagName() == QLatin1String(PEP_AVATAR_METADATA_TN) && item.payload().firstChildElement().isNull()) { result = AvatarCache::instance()->removeIcon(AvatarCache::AvatarType, jidFull); } else { + auto id = item.id().toLatin1(); + if (id == "current") { + return; // probably was in previous versions of xep + } + QByteArray hash = QByteArray::fromHex(id); + if (hash.size() < 20) { + // qDebug() << "not sha1"; + return; // doesn't look like sha1 hash. just ignore it + } + VCardFactory::instance()->ensureVCardUpdated(pa, jid, VCardFactory::InterestPhoto, hash); for (QDomElement e = item.payload().firstChildElement(QLatin1String("info")); !e.isNull(); @@ -693,6 +693,7 @@ class AvatarCache : public FileCache { jids.append(typedJid(iconType, jid)); md.insert(QLatin1String("jids"), jids); item->setMetadata(md); + lazySync(); } if (prevIcon) { @@ -723,6 +724,7 @@ class AvatarCache : public FileCache { } else { md.insert(QLatin1String("jids"), jids); item->setMetadata(md); + lazySync(); } } @@ -804,6 +806,7 @@ class AvatarCache : public FileCache { if (jidsChanged) { md.insert(QLatin1String("jids"), jids); it.value()->setMetadata(md); + lazySync(); } } } @@ -932,7 +935,7 @@ void AvatarFactory::setSelfAvatar(const QString &fileName) account()->pepManager()->publish(PEP_AVATAR_DATA_NS, PubSubItem(id, el)); } } else { - account()->pepManager()->disable(PEP_AVATAR_METADATA_TN, PEP_AVATAR_METADATA_NS, "current"); + account()->pepManager()->disable(PEP_AVATAR_METADATA_TN, PEP_AVATAR_METADATA_NS, {}); } } @@ -959,8 +962,9 @@ void AvatarFactory::statusUpdate(const Jid &jid, const XMPP::Status &status, Fla void AvatarFactory::ensureVCardUpdated(const Jid &jid, const QByteArray &hash, Flags flags) { if (!AvatarCache::instance()->ensureVCardUpdated(jid, hash, flags)) { - VCardFactory::instance()->ensureVCardUpdated(d->pa_, jid, flags2AvatarFlags(flags), hash); + // must request vcard } + VCardFactory::instance()->ensureVCardUpdated(d->pa_, jid, flags2AvatarFlags(flags), hash); } QString AvatarFactory::getCacheDir() diff --git a/src/filecache.cpp b/src/filecache.cpp index 9bd1bbd71..902446cb7 100644 --- a/src/filecache.cpp +++ b/src/filecache.cpp @@ -307,8 +307,14 @@ bool ctimeLessThan(FileCacheItem *a, FileCacheItem *b) { return a->created() < b void FileCache::sync() { sync(false); } +void FileCache::lazySync() { _syncTimer->start(); } + void FileCache::sync(bool finishSession) { + if (_syncTimer->isActive()) { + _syncTimer->stop(); + } + QList loadedItems; QList onDiskItems; qint64 sumMemorySize = 0; @@ -333,8 +339,9 @@ void FileCache::sync(bool finishSession) sumFileSize += item->size(); onDiskItems.append(item); } - } else if (!item->isRegistered()) { // just put to registry item without data and stop reviewing it - toRegistry(item); // save item to registry if not yet + } + if (!item->isRegistered()) { // just put to registry item without data and stop reviewing it + toRegistry(item); // save item to registry if not yet } } @@ -351,9 +358,9 @@ void FileCache::sync(bool finishSession) } item->unload(); // will flush data to disk if necesary sumMemorySize -= item->size(); - if (!item->isRegistered()) { - toRegistry(item); // save item to registry if not yet - } + // if (!item->isRegistered()) { + // toRegistry(item); // save item to registry if not yet + // } } } diff --git a/src/filecache.h b/src/filecache.h index f9d2014c3..f22c5d8b4 100644 --- a/src/filecache.h +++ b/src/filecache.h @@ -187,6 +187,7 @@ class FileCache : public QObject { public slots: void sync(); + void lazySync(); private: void toRegistry(FileCacheItem *); diff --git a/src/pepmanager.cpp b/src/pepmanager.cpp index 9e9b3fdcc..768b403b1 100644 --- a/src/pepmanager.cpp +++ b/src/pepmanager.cpp @@ -240,7 +240,9 @@ class PEPPublishTask : public Task { pubsub.appendChild(publish); QDomElement item = doc()->createElement("item"); - item.setAttribute("id", it.id()); + if (!it.id().isEmpty()) { + item.setAttribute("id", it.id()); + } publish.appendChild(item); if (access != PEPManager::DefaultAccess) { diff --git a/src/vcardfactory.cpp b/src/vcardfactory.cpp index 7ef541f43..b8398b24e 100644 --- a/src/vcardfactory.cpp +++ b/src/vcardfactory.cpp @@ -321,11 +321,17 @@ VCardFactory::QueuedLoader::QueuedLoader(VCardFactory *vcf) : QObject(vcf), q(vc timer_.setSingleShot(false); timer_.setInterval(VcardReqInterval); QObject::connect(&timer_, &QTimer::timeout, this, [this]() { + if (queue_.isEmpty()) { + timer_.stop(); + return; + } auto request = queue_.takeFirst(); auto task = request->execute(); if (task) { connect(task, &JT_VCard::finished, this, [this, request]() { - // qDebug() << "received VCardRequest" << request->jid().full(); +#ifdef VCF_DEBUG + qDebug() << "received VCardRequest" << request->jid().full(); +#endif emit vcardReceived(request); jid2req.remove(request->jid()); request->deleteLater(); @@ -350,12 +356,16 @@ VCardRequest *VCardFactory::QueuedLoader::enqueue(PsiAccount *acc, const Jid &ji } auto req = jid2req[sanitized_jid]; if (!req) { - // qDebug() << "new VCardRequest" << sanitized_jid.full() << flags; +#ifdef VCF_DEBUG + qDebug() << "new VCardRequest" << sanitized_jid.full() << flags; +#endif req = new VCardRequest(acc, sanitized_jid, flags); jid2req[sanitized_jid] = req; queue_.append(req); } else { - // qDebug() << "merge VCardRequest" << sanitized_jid.full() << flags; +#ifdef VCF_DEBUG + qDebug() << "merge VCardRequest" << sanitized_jid.full() << flags; +#endif req->merge(acc, sanitized_jid, flags); } diff --git a/version b/version index 17fdff4e9..a18d76076 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.5.1942 (2024-06-04, 314403d9) +1.5.1943 (2024-06-05, afa459a0)