Skip to content

Commit

Permalink
Current version of Psi+ is 1.5.1941
Browse files Browse the repository at this point in the history
It is based on:
* psi: 319598eb
* plugins: 7a65467
* psimedia: 478567e
* resources: e32ef4b
  • Loading branch information
tehnick committed Jun 2, 2024
1 parent b296942 commit c23cd40
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 35 deletions.
66 changes: 33 additions & 33 deletions src/avatars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,32 +176,26 @@ class AvatarCache : public FileCache {
qWarning("avatars.cpp: Unexpected item payload");
}
} else if (n == PEP_AVATAR_METADATA_NS) {
auto id = item.id().toLatin1();
bool isCurrent = id == "current";
QByteArray hash;
if (!isCurrent) {
hash = QByteArray::fromHex(id);
if (hash.size() < 20) {
// qDebug() << "not sha1";
return; // doesn't look like sha1 hash. just ignore it
}
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()->getVCard(pa, jid, VCardFactory::InterestPhoto);

if (item.payload().tagName() == QLatin1String(PEP_AVATAR_METADATA_TN)
&& item.payload().firstChildElement().isNull()) {
// user wants to stop publishing avatar
// previously we used "stop" element. now specs are changed
// qDebug() << "remove AvatarType from cache" << jidFull;
result = AvatarCache::instance()->removeIcon(AvatarCache::AvatarType, jidFull);
} else {
auto mimes = QImageReader::supportedMimeTypes();
VCardFactory::instance()->ensureVCardUpdated(pa, jid, VCardFactory::InterestPhoto, hash);

for (QDomElement e = item.payload().firstChildElement(QLatin1String("info")); !e.isNull();
e = e.nextSiblingElement(QLatin1String("info"))) {
if (!mimes.contains(e.attribute(QLatin1String("type")).toLower().toLatin1())) {
continue; // unsupported mime
if (e.attribute(QLatin1String("type")).toLower() != QLatin1String("image/png")) {
continue; // TODO add support for QImageReader::supportedMimeTypes() (requires usage of qnam)
}
if (!e.attribute(QLatin1String("url")).isEmpty()) {
continue; // web avatars are not currently supported. TODO but their support is highly expected
Expand All @@ -220,9 +214,11 @@ class AvatarCache : public FileCache {
}
}

// qDebug() << "remove from iconset" << jidFull;
iconset_->removeIcon(QString(QLatin1String("avatars/%1")).arg(jidFull));
emit avatarChanged(jidFull);
if (result == UserUpdateRequired) {
// qDebug() << "remove from iconset" << jidFull;
iconset_->removeIcon(QString(QLatin1String("avatars/%1")).arg(jidFull));
emit avatarChanged(jidFull);
}
}

bool ensureVCardUpdated(const Jid &jid, const QByteArray &hash, AvatarFactory::Flags flags)
Expand Down Expand Up @@ -915,21 +911,25 @@ AvatarFactory::UserHashes AvatarFactory::userHashes(const Jid &jid) const
void AvatarFactory::setSelfAvatar(const QString &fileName)
{
if (!fileName.isEmpty()) {
QFile avatar_file(fileName);
if (!avatar_file.open(QIODevice::ReadOnly))
return;

QByteArray avatar_data = scaleAvatar(avatar_file.readAll());
QImage avatar_image = QImage::fromData(avatar_data);
if (!avatar_image.isNull()) {
QImage image(fileName);
if (!image.isNull()) {
// Publish data

QByteArray data;
QBuffer buffer(&data);
buffer.open(QIODevice::WriteOnly);
auto maxSz = maxAvatarSize();
image.scaled(image.size().boundedTo(QSize(maxSz, maxSz)), Qt::KeepAspectRatio, Qt::SmoothTransformation)
.save(&buffer, "PNG", 0);
auto hash = QCryptographicHash::hash(data, QCryptographicHash::Sha1);
QString id = QString::fromLatin1(hash.toHex());

QDomDocument *doc = account()->client()->doc();
QString hash = QString::fromLatin1(QCryptographicHash::hash(avatar_data, QCryptographicHash::Sha1).toHex());
QDomElement el = doc->createElementNS(PEP_AVATAR_DATA_NS, PEP_AVATAR_DATA_TN);
el.appendChild(doc->createTextNode(QString::fromLatin1(avatar_data.toBase64())));
d->selfAvatarData_ = avatar_data;
d->selfAvatarHash_ = hash;
account()->pepManager()->publish(PEP_AVATAR_DATA_NS, PubSubItem(hash, el));
QDomElement el = doc->createElementNS(PEP_AVATAR_DATA_NS, PEP_AVATAR_DATA_TN);
el.appendChild(doc->createTextNode(QString::fromLatin1(data.toBase64())));
d->selfAvatarData_ = data;
d->selfAvatarHash_ = id;
account()->pepManager()->publish(PEP_AVATAR_DATA_NS, PubSubItem(id, el));
}
} else {
account()->pepManager()->disable(PEP_AVATAR_METADATA_TN, PEP_AVATAR_METADATA_NS, "current");
Expand Down
7 changes: 7 additions & 0 deletions src/infodlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ InfoWidget::InfoWidget(int type, const Jid &j, const VCard &vcard, PsiAccount *p
d->userListItem->userResourceList() = url;
updateStatus();
requestResourceInfo(j);
if (s.photoHash()) {
VCardFactory::instance()->ensureVCardUpdated(
d->pa, j, VCardFactory::InterestPhoto | VCardFactory::MucUser, *s.photoHash());
}
}
});
} else {
Expand Down Expand Up @@ -910,6 +914,9 @@ void InfoWidget::updateStatus()
}
}
PsiRichText::setText(m_ui.te_status->document(), info);
auto cursor = m_ui.te_status->textCursor();
cursor.setPosition(0);
m_ui.te_status->setTextCursor(cursor);
} else {
m_ui.te_status->clear();
}
Expand Down
11 changes: 10 additions & 1 deletion src/vcardfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ void VCardFactory::ensureVCardUpdated(PsiAccount *acc, const Jid &jid, Flags fla
}
if (!vc || (flags & InterestPhoto && 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";
// }
queuedLoader_->enqueue(acc, jid, flags, QueuedLoader::NormalPriority);
}
}
Expand Down Expand Up @@ -320,6 +325,7 @@ VCardFactory::QueuedLoader::QueuedLoader(VCardFactory *vcf) : QObject(vcf), q(vc
auto task = request->execute();
if (task) {
connect(task, &JT_VCard::finished, this, [this, request]() {
// qDebug() << "received VCardRequest" << request->jid().full();
emit vcardReceived(request);
jid2req.remove(request->jid());
request->deleteLater();
Expand All @@ -344,9 +350,12 @@ VCardRequest *VCardFactory::QueuedLoader::enqueue(PsiAccount *acc, const Jid &ji
}
auto req = jid2req[sanitized_jid];
if (!req) {
req = new VCardRequest(acc, sanitized_jid, flags);
// qDebug() << "new VCardRequest" << sanitized_jid.full() << flags;
req = new VCardRequest(acc, sanitized_jid, flags);
jid2req[sanitized_jid] = req;
queue_.append(req);
} else {
// qDebug() << "merge VCardRequest" << sanitized_jid.full() << flags;
req->merge(acc, sanitized_jid, flags);
}

Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.1940 (2024-06-02, d3389574)
1.5.1941 (2024-06-03, 319598eb)

0 comments on commit c23cd40

Please sign in to comment.