From 8af056faa96e3304c22e20c2bee1de22d77269ae Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 7 Sep 2020 18:11:06 +0200 Subject: [PATCH] Fix avatars in notifications --- src/AvatarProvider.cpp | 13 +++++++------ src/ChatPage.cpp | 24 ++++++++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/AvatarProvider.cpp b/src/AvatarProvider.cpp index 603bb71a..b1751c33 100644 --- a/src/AvatarProvider.cpp +++ b/src/AvatarProvider.cpp @@ -34,10 +34,12 @@ resolve(const QString &avatarUrl, int size, QObject *receiver, AvatarCallback ca { const auto cacheKey = QString("%1_size_%2").arg(avatarUrl).arg(size); - if (avatarUrl.isEmpty()) - return; - QPixmap pixmap; + if (avatarUrl.isEmpty()) { + callback(pixmap); + return; + } + if (avatar_cache.find(cacheKey, &pixmap)) { callback(pixmap); return; @@ -75,11 +77,10 @@ resolve(const QString &avatarUrl, int size, QObject *receiver, AvatarCallback ca opts.mxc_url, mtx::errors::to_string(err->matrix_error.errcode), err->matrix_error.error); - return; + } else { + cache::saveImage(cacheKey.toStdString(), res); } - cache::saveImage(cacheKey.toStdString(), res); - emit proxy->avatarDownloaded(QByteArray(res.data(), res.size())); }); } diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index cf1a6062..6008846a 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -895,14 +895,22 @@ ChatPage::sendNotifications(const mtx::responses::Notifications &res) } if (userSettings_->hasDesktopNotifications()) { - notificationsManager.postNotification( - room_id, - QString::fromStdString(event_id), - QString::fromStdString( - cache::singleRoomInfo(item.room_id).name), - cache::displayName(room_id, user_id), - utils::event_body(item.event), - cache::getRoomAvatar(room_id)); + auto info = cache::singleRoomInfo(item.room_id); + + AvatarProvider::resolve( + QString::fromStdString(info.avatar_url), + 96, + this, + [this, room_id, event_id, item, user_id, info]( + QPixmap image) { + notificationsManager.postNotification( + room_id, + QString::fromStdString(event_id), + QString::fromStdString(info.name), + cache::displayName(room_id, user_id), + utils::event_body(item.event), + image.toImage()); + }); } } } catch (const lmdb::error &e) {