From e224440f5df4e39df3fed5f30e13c773a65fe01b Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 28 Oct 2017 21:11:40 +0300 Subject: [PATCH] Display user avatar changes --- include/AvatarProvider.h | 12 +++++++++--- src/AvatarProvider.cc | 42 ++++++++++++++++++++++------------------ src/EmojiPickButton.cc | 2 +- src/Login.cc | 2 +- src/LoginPage.cc | 2 +- src/Profile.cc | 1 + src/Register.cc | 1 + src/RegisterPage.cc | 2 +- 8 files changed, 38 insertions(+), 26 deletions(-) diff --git a/include/AvatarProvider.h b/include/AvatarProvider.h index a58ef0b7..906f2593 100644 --- a/include/AvatarProvider.h +++ b/include/AvatarProvider.h @@ -24,6 +24,12 @@ class MatrixClient; class TimelineItem; +struct AvatarData +{ + QImage img; + QUrl url; +}; + class AvatarProvider : public QObject { Q_OBJECT @@ -39,8 +45,8 @@ private: static void updateAvatar(const QString &uid, const QImage &img); static QSharedPointer client_; - static QMap> toBeResolved_; - static QMap userAvatars_; - static QMap avatarUrls_; + using UserID = QString; + static QMap avatars_; + static QMap> toBeResolved_; }; diff --git a/src/AvatarProvider.cc b/src/AvatarProvider.cc index ab938cb1..7e8c9e49 100644 --- a/src/AvatarProvider.cc +++ b/src/AvatarProvider.cc @@ -21,8 +21,7 @@ QSharedPointer AvatarProvider::client_; -QMap AvatarProvider::userAvatars_; -QMap AvatarProvider::avatarUrls_; +QMap AvatarProvider::avatars_; QMap> AvatarProvider::toBeResolved_; void @@ -46,45 +45,50 @@ AvatarProvider::updateAvatar(const QString &uid, const QImage &img) toBeResolved_.remove(uid); } - userAvatars_.insert(uid, img); + auto avatarData = avatars_[uid]; + avatarData.img = img; + + avatars_.insert(uid, avatarData); } void AvatarProvider::resolve(const QString &userId, TimelineItem *item) { - if (userAvatars_.contains(userId)) { - auto img = userAvatars_[userId]; + if (!avatars_.contains(userId)) + return; + auto img = avatars_[userId].img; + + if (!img.isNull()) { item->setUserAvatar(img); - return; } - if (avatarUrls_.contains(userId)) { - // Add the current timeline item to the waiting list for this avatar. - if (!toBeResolved_.contains(userId)) { - client_->fetchUserAvatar(userId, avatarUrls_[userId]); + // Add the current timeline item to the waiting list for this avatar. + if (!toBeResolved_.contains(userId)) { + client_->fetchUserAvatar(userId, avatars_[userId].url); - QList timelineItems; - timelineItems.push_back(item); + QList timelineItems; + timelineItems.push_back(item); - toBeResolved_.insert(userId, timelineItems); - } else { - toBeResolved_[userId].push_back(item); - } + toBeResolved_.insert(userId, timelineItems); + } else { + toBeResolved_[userId].push_back(item); } } void AvatarProvider::setAvatarUrl(const QString &userId, const QUrl &url) { - avatarUrls_.insert(userId, url); + AvatarData data; + data.url = url; + + avatars_.insert(userId, data); } void AvatarProvider::clear() { - userAvatars_.clear(); - avatarUrls_.clear(); + avatars_.clear(); toBeResolved_.clear(); } diff --git a/src/EmojiPickButton.cc b/src/EmojiPickButton.cc index 17716f6f..a63ca0b2 100644 --- a/src/EmojiPickButton.cc +++ b/src/EmojiPickButton.cc @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#include "EmojiPanel.h" #include "EmojiPickButton.h" +#include "EmojiPanel.h" EmojiPickButton::EmojiPickButton(QWidget *parent) : FlatButton(parent) diff --git a/src/Login.cc b/src/Login.cc index 69338f2c..a9e303f9 100644 --- a/src/Login.cc +++ b/src/Login.cc @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#include "Deserializable.h" #include "Login.h" +#include "Deserializable.h" LoginRequest::LoginRequest() {} diff --git a/src/LoginPage.cc b/src/LoginPage.cc index c1ba352c..528b7442 100644 --- a/src/LoginPage.cc +++ b/src/LoginPage.cc @@ -15,11 +15,11 @@ * along with this program. If not, see . */ +#include "LoginPage.h" #include "Config.h" #include "FlatButton.h" #include "InputValidator.h" #include "LoadingIndicator.h" -#include "LoginPage.h" #include "MatrixClient.h" #include "OverlayModal.h" #include "RaisedButton.h" diff --git a/src/Profile.cc b/src/Profile.cc index 38795e49..8eaafe07 100644 --- a/src/Profile.cc +++ b/src/Profile.cc @@ -16,6 +16,7 @@ */ #include "Deserializable.h" + #include "Profile.h" void diff --git a/src/Register.cc b/src/Register.cc index 0fe2ddce..7453c943 100644 --- a/src/Register.cc +++ b/src/Register.cc @@ -16,6 +16,7 @@ */ #include "Deserializable.h" + #include "Register.h" RegisterRequest::RegisterRequest(const QString &username, const QString &password) diff --git a/src/RegisterPage.cc b/src/RegisterPage.cc index d8186f65..304a7dc0 100644 --- a/src/RegisterPage.cc +++ b/src/RegisterPage.cc @@ -15,13 +15,13 @@ * along with this program. If not, see . */ +#include "RegisterPage.h" #include "Avatar.h" #include "Config.h" #include "FlatButton.h" #include "InputValidator.h" #include "MatrixClient.h" #include "RaisedButton.h" -#include "RegisterPage.h" #include "TextField.h" RegisterPage::RegisterPage(QSharedPointer client, QWidget *parent)