diff --git a/src/notifications/Manager.cpp b/src/notifications/Manager.cpp
index 8a3576c5..b4a3a3da 100644
--- a/src/notifications/Manager.cpp
+++ b/src/notifications/Manager.cpp
@@ -24,7 +24,7 @@ NotificationsManager::cacheImage(const mtx::events::collections::TimelineEvents
http::client()->download(
url,
- [path, url, encryptionInfo](const std::string &data,
+ [&path, url, encryptionInfo](const std::string &data,
const std::string &,
const std::string &,
mtx::http::RequestErr err) {
@@ -53,10 +53,11 @@ NotificationsManager::cacheImage(const mtx::events::collections::TimelineEvents
// resize the image
QImage img{utils::readImage(QByteArray{temp.data()})};
- // make sure to save as PNG (because Plasma doesn't do JPEG in
- // notifications)
- // if (!file.fileName().endsWith(".png"))
- // file.rename(file.fileName() + ".png");
+ if (img.isNull())
+ {
+ path.clear();
+ return;
+ }
#ifdef NHEKO_DBUS_SYS // the images in D-Bus notifications are to be 200x100 max
img.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation)
diff --git a/src/notifications/ManagerLinux.cpp b/src/notifications/ManagerLinux.cpp
index cd9d6fb8..0cf61d5c 100644
--- a/src/notifications/ManagerLinux.cpp
+++ b/src/notifications/ManagerLinux.cpp
@@ -216,12 +216,18 @@ NotificationsManager::formatNotification(const mtx::responses::Notification ¬
if (hasMarkup_) {
if (hasImages_ &&
mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image)
+ {
+ QString imgPath = cacheImage(notification.event);
+ if (imgPath.isNull())
+ return mtx::accessors::formattedBodyWithFallback(notification.event).prepend(messageLeadIn);
+ else
return QString(
- "<img src=\"file:///" + cacheImage(notification.event) +
+ "<img src=\"file:///" + imgPath +
"\" alt=\"" +
mtx::accessors::formattedBodyWithFallback(notification.event) +
"\">")
.prepend(messageLeadIn);
+ }
return mtx::accessors::formattedBodyWithFallback(notification.event)
.prepend(messageLeadIn)
diff --git a/src/notifications/ManagerMac.cpp b/src/notifications/ManagerMac.cpp
index 8b6b3bd9..7e3ad309 100644
--- a/src/notifications/ManagerMac.cpp
+++ b/src/notifications/ManagerMac.cpp
@@ -58,6 +58,6 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
const QString messageInfo =
(isReply ? tr("%1 replied to a message") : tr("%1 sent a message")).arg(sender);
objCxxPostNotification(
- room_name, messageInfo, formatNotification(notification), image);
+ room_name, messageInfo, formatNotification(notification), (image != nullptr && !image->isNull()) ? image : nullptr);
}
}
|