Skip to content

Commit

Permalink
Current version of Psi+ is 1.5.1947
Browse files Browse the repository at this point in the history
It is based on:
* psi: a7848ee9
* plugins: 7a65467
* psimedia: 478567e
* resources: e32ef4b
  • Loading branch information
tehnick committed Jun 5, 2024
1 parent 2e45826 commit ef7b18e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 50 deletions.
10 changes: 6 additions & 4 deletions src/avatars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ QByteArray scaleAvatar(const QByteArray &b)

VCardFactory::Flags flags2AvatarFlags(AvatarFactory::Flags flags)
{
VCardFactory::Flags ret = VCardFactory::InterestPhoto;
VCardFactory::Flags ret;
if (flags & AvatarFactory::MucRoom) {
ret |= VCardFactory::MucRoom;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ class AvatarCache : public FileCache {
return; // doesn't look like sha1 hash. just ignore it
}

VCardFactory::instance()->ensureVCardUpdated(pa, jid, VCardFactory::InterestPhoto, hash);
VCardFactory::instance()->ensureVCardPhotoUpdated(pa, jid, {}, hash);

for (; !info.isNull(); info = info.nextSiblingElement(QLatin1String("info"))) {
if (info.attribute(QLatin1String("type")).toLower() != QLatin1String("image/png")) {
Expand Down Expand Up @@ -995,8 +995,10 @@ void AvatarFactory::ensureVCardUpdated(const Jid &jid, const QByteArray &hash, F
{
if (!AvatarCache::instance()->ensureVCardUpdated(jid, hash, flags)) {
// must request vcard
}
VCardFactory::instance()->ensureVCardUpdated(d->pa_, jid, flags2AvatarFlags(flags), hash);
} // else we need to remember jid has new hash but vcard is not necessary at the moment

// force request till we figure out how to follow comments above
VCardFactory::instance()->ensureVCardPhotoUpdated(d->pa_, jid, flags2AvatarFlags(flags), hash);
}

QString AvatarFactory::getCacheDir()
Expand Down
3 changes: 1 addition & 2 deletions src/infodlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ InfoWidget::InfoWidget(int type, const Jid &j, const VCard &vcard, PsiAccount *p
updateStatus();
requestResourceInfo(j);
if (s.photoHash()) {
VCardFactory::instance()->ensureVCardUpdated(
d->pa, j, VCardFactory::InterestPhoto | VCardFactory::MucUser, *s.photoHash());
VCardFactory::instance()->ensureVCardPhotoUpdated(d->pa, j, VCardFactory::MucUser, *s.photoHash());
}
}
});
Expand Down
67 changes: 35 additions & 32 deletions src/vcardfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,7 @@ VCardFactory::VCardFactory() : QObject(qApp), dictSize_(5), queuedLoader_(new Qu
{
connect(queuedLoader_, &QueuedLoader::vcardReceived, this, [this](const VCardRequest *request) {
if (request->success()) {
if (request->flags() & MucUser) {
Jid j = request->jid();
auto &nick2vcard = mucVcardDict_[j.bare()];
auto nickIt = nick2vcard.find(j.resource());
if (nickIt == nick2vcard.end()) {
nick2vcard.insert(j.resource(), request->vcard());
auto &resQueue = lastMucVcards_[j.bare()];
resQueue.enqueue(j.resource());
while (resQueue.size() > 3) { // keep max 3 vcards per muc
nick2vcard.remove(resQueue.dequeue());
}
} else {
*nickIt = request->vcard();
}

emit vcardChanged(j, request->flags());
} else {
saveVCard(request->jid(), request->vcard(), request->flags());
}
saveVCard(request->jid(), request->vcard(), request->flags());
}
#ifdef VCF_DEBUG
else {
Expand Down Expand Up @@ -131,8 +113,26 @@ void VCardFactory::checkLimit(const QString &jid, const VCard &vcard)
void VCardFactory::saveVCard(const Jid &j, const VCard &vcard, Flags flags)
{
#ifdef VCF_DEBUG
qDebug() << "VCardFactory::saveVCard" << j.bare();
qDebug() << "VCardFactory::saveVCard" << j.full();
#endif
if (flags & MucUser) {

auto &nick2vcard = mucVcardDict_[j.bare()];
auto nickIt = nick2vcard.find(j.resource());
if (nickIt == nick2vcard.end()) {
nick2vcard.insert(j.resource(), vcard);
auto &resQueue = lastMucVcards_[j.bare()];
resQueue.enqueue(j.resource());
while (resQueue.size() > 3) { // keep max 3 vcards per muc
nick2vcard.remove(resQueue.dequeue());
}
} else {
*nickIt = vcard;
}

emit vcardChanged(j, flags);
return;
}

checkLimit(j.bare(), vcard);

Expand Down Expand Up @@ -235,25 +235,28 @@ VCardRequest *VCardFactory::getVCard(PsiAccount *account, const Jid &jid, Flags
return queuedLoader_->enqueue(account, jid, flags, QueuedLoader::HighPriority);
}

void VCardFactory::ensureVCardUpdated(PsiAccount *acc, const Jid &jid, Flags flags, const QByteArray &photoHash)
void VCardFactory::ensureVCardPhotoUpdated(PsiAccount *acc, const Jid &jid, Flags flags, const QByteArray &newPhotoHash)
{
VCard vc;
if (flags & MucUser) {
vc = mucVcard(jid);
} else {
vc = vcard(jid);
}
if (!vc
|| (flags & InterestPhoto
&& (vc.photo().isEmpty() != photoHash.isEmpty()
|| (!vc.photo().isEmpty()
&& QCryptographicHash::hash(vc.photo(), QCryptographicHash::Sha1) != photoHash)))) {
// FIXME computing hash everytime is not quite cool. We need to store it in metadata like in FileCache
// if (vc) {
// qDebug() << QCryptographicHash::hash(vc.photo(), QCryptographicHash::Sha1).toHex() << photoHash.toHex();
// } else {
// qDebug() << "no vcard";
// }
if (newPhotoHash.isEmpty()) {
if (!vc || vc.photo().isEmpty()) { // we didn't have it and still don't
return;
}
vc.setPhoto({}); // reset photo;
saveVCard(jid, vc, flags);

return;
}
auto oldHash = vc ? QCryptographicHash::hash(vc.photo(), QCryptographicHash::Sha1) : QByteArray();
if (oldHash != newPhotoHash) {
#ifdef VCF_DEBUG
qDebug() << "hash mismatch. old=" << oldHash.toHex() << "new=" << photoHash.toHex();
#endif
queuedLoader_->enqueue(acc, jid, flags, QueuedLoader::NormalPriority);
}
}
Expand Down
17 changes: 6 additions & 11 deletions src/vcardfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <QObject>
#include <QStringList>

#include <functional>
#include <memory>

class PsiAccount;
Expand All @@ -45,12 +44,9 @@ class VCardFactory : public QObject {

public:
enum Flag {
MucRoom = 0x1,
MucUser = 0x2,
Cache = 0x4,
InterestInfo = 0x8, // text data
InterestPhoto = 0x10, // graphics. photoHash MUST be provided
InterestAll = InterestInfo | InterestPhoto
MucRoom = 0x1,
MucUser = 0x2,
Cache = 0x4,
};
Q_DECLARE_FLAGS(Flags, Flag);

Expand All @@ -60,13 +56,12 @@ class VCardFactory : public QObject {
// void setVCard(const Jid &, const VCard &);

JT_VCard *setVCard(const PsiAccount *account, const VCard &v, const Jid &targetJid, VCardFactory::Flags flags);
VCardRequest *getVCard(PsiAccount *account, const Jid &, VCardFactory::Flags flags = InterestInfo);
VCardRequest *getVCard(PsiAccount *account, const Jid &, VCardFactory::Flags flags = {});

// 1. check if it's needed to do a request,
// 2. enqueue request if necessary (no vcard, or if InterestPhoto then also if hash doesn't match)
// 2. enqueue request if necessary (no vcard, or if hash doesn't match)
// 3. vcardChanged() will be sent as usually when vcard is updated
void ensureVCardUpdated(PsiAccount *acc, const Jid &jid, Flags flags = InterestInfo,
const QByteArray &photoHash = {});
void ensureVCardPhotoUpdated(PsiAccount *acc, const Jid &jid, Flags flags, const QByteArray &newPhotoHash);

signals:
void vcardChanged(const Jid &, VCardFactory::Flags);
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.1946 (2024-06-05, c9955acc)
1.5.1947 (2024-06-06, a7848ee9)

0 comments on commit ef7b18e

Please sign in to comment.