Skip to content
Snippets Groups Projects
Commit 74cbfb6f authored by Nicolas Werner's avatar Nicolas Werner
Browse files

[konheko] Show room avatar in notifications

parent 96aea770
No related branches found
No related tags found
No related merge requests found
......@@ -2,13 +2,17 @@
#include <QGuiApplication>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QImage>
#include <QImageReader>
#include <QMediaMetaData>
#include <QMediaPlayer>
#include <QMetaType>
#include <QRegularExpression>
#include <QSharedPointer>
#include <QStandardPaths>
#include <QtMath>
#include <QDebug>
......@@ -283,7 +287,37 @@ Room::Room(QObject *parent) : loadingOlderMessages(false) {
n.setPreviewSummary(roomName());
n.setPreviewBody(userIdToUserName(this->msgInfo.userid) + ": " + this->msgInfo.body);
n.setTimestamp(this->msgInfo.datetime);
n.setHintValue("x-nemo-priority", 101);
n.setUrgency(Notification::Normal);
if (!avatar_url_.isEmpty()) {
auto name = avatarUrl().remove("mxc://");
auto cacheFile = QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" +
name + "_128x128");
if (QDir::cleanPath(name) == name) {
if (!cacheFile.exists()) {
mtx::http::ThumbOpts opts;
opts.mxc_url = "mxc://" + name.toStdString();
opts.width = 128;
opts.height = 128;
opts.method = "scale";
http::client().get_thumbnail(
opts, [this, cacheFile, name](const std::string &res, mtx::http::RequestErr err) {
if (err) {
return;
}
QImage m_image;
auto data = QByteArray(res.data(), res.size());
m_image.loadFromData(data);
m_image = m_image.scaled(QSize(128, 128), Qt::KeepAspectRatio);
m_image.setText("mxc url", "mxc://" + name);
QDir().mkpath(cacheFile.path());
m_image.save(cacheFile.filePath(), "png");
});
}
n.setIcon(cacheFile.filePath());
}
}
QVariantList arguments;
arguments.append(QString::fromStdString(id));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment