Display user avatar changes

This commit is contained in:
Konstantinos Sideris 2017-10-28 21:11:40 +03:00
parent c18a49915b
commit e224440f5d
8 changed files with 38 additions and 26 deletions

View file

@ -24,6 +24,12 @@
class MatrixClient; class MatrixClient;
class TimelineItem; class TimelineItem;
struct AvatarData
{
QImage img;
QUrl url;
};
class AvatarProvider : public QObject class AvatarProvider : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -39,8 +45,8 @@ private:
static void updateAvatar(const QString &uid, const QImage &img); static void updateAvatar(const QString &uid, const QImage &img);
static QSharedPointer<MatrixClient> client_; static QSharedPointer<MatrixClient> client_;
static QMap<QString, QList<TimelineItem *>> toBeResolved_;
static QMap<QString, QImage> userAvatars_; using UserID = QString;
static QMap<QString, QUrl> avatarUrls_; static QMap<UserID, AvatarData> avatars_;
static QMap<UserID, QList<TimelineItem *>> toBeResolved_;
}; };

View file

@ -21,8 +21,7 @@
QSharedPointer<MatrixClient> AvatarProvider::client_; QSharedPointer<MatrixClient> AvatarProvider::client_;
QMap<QString, QImage> AvatarProvider::userAvatars_; QMap<QString, AvatarData> AvatarProvider::avatars_;
QMap<QString, QUrl> AvatarProvider::avatarUrls_;
QMap<QString, QList<TimelineItem *>> AvatarProvider::toBeResolved_; QMap<QString, QList<TimelineItem *>> AvatarProvider::toBeResolved_;
void void
@ -46,24 +45,28 @@ AvatarProvider::updateAvatar(const QString &uid, const QImage &img)
toBeResolved_.remove(uid); toBeResolved_.remove(uid);
} }
userAvatars_.insert(uid, img); auto avatarData = avatars_[uid];
avatarData.img = img;
avatars_.insert(uid, avatarData);
} }
void void
AvatarProvider::resolve(const QString &userId, TimelineItem *item) AvatarProvider::resolve(const QString &userId, TimelineItem *item)
{ {
if (userAvatars_.contains(userId)) { if (!avatars_.contains(userId))
auto img = userAvatars_[userId]; return;
auto img = avatars_[userId].img;
if (!img.isNull()) {
item->setUserAvatar(img); item->setUserAvatar(img);
return; return;
} }
if (avatarUrls_.contains(userId)) {
// Add the current timeline item to the waiting list for this avatar. // Add the current timeline item to the waiting list for this avatar.
if (!toBeResolved_.contains(userId)) { if (!toBeResolved_.contains(userId)) {
client_->fetchUserAvatar(userId, avatarUrls_[userId]); client_->fetchUserAvatar(userId, avatars_[userId].url);
QList<TimelineItem *> timelineItems; QList<TimelineItem *> timelineItems;
timelineItems.push_back(item); timelineItems.push_back(item);
@ -73,18 +76,19 @@ AvatarProvider::resolve(const QString &userId, TimelineItem *item)
toBeResolved_[userId].push_back(item); toBeResolved_[userId].push_back(item);
} }
} }
}
void void
AvatarProvider::setAvatarUrl(const QString &userId, const QUrl &url) AvatarProvider::setAvatarUrl(const QString &userId, const QUrl &url)
{ {
avatarUrls_.insert(userId, url); AvatarData data;
data.url = url;
avatars_.insert(userId, data);
} }
void void
AvatarProvider::clear() AvatarProvider::clear()
{ {
userAvatars_.clear(); avatars_.clear();
avatarUrls_.clear();
toBeResolved_.clear(); toBeResolved_.clear();
} }

View file

@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "EmojiPanel.h"
#include "EmojiPickButton.h" #include "EmojiPickButton.h"
#include "EmojiPanel.h"
EmojiPickButton::EmojiPickButton(QWidget *parent) EmojiPickButton::EmojiPickButton(QWidget *parent)
: FlatButton(parent) : FlatButton(parent)

View file

@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Deserializable.h"
#include "Login.h" #include "Login.h"
#include "Deserializable.h"
LoginRequest::LoginRequest() {} LoginRequest::LoginRequest() {}

View file

@ -15,11 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "LoginPage.h"
#include "Config.h" #include "Config.h"
#include "FlatButton.h" #include "FlatButton.h"
#include "InputValidator.h" #include "InputValidator.h"
#include "LoadingIndicator.h" #include "LoadingIndicator.h"
#include "LoginPage.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "OverlayModal.h" #include "OverlayModal.h"
#include "RaisedButton.h" #include "RaisedButton.h"

View file

@ -16,6 +16,7 @@
*/ */
#include "Deserializable.h" #include "Deserializable.h"
#include "Profile.h" #include "Profile.h"
void void

View file

@ -16,6 +16,7 @@
*/ */
#include "Deserializable.h" #include "Deserializable.h"
#include "Register.h" #include "Register.h"
RegisterRequest::RegisterRequest(const QString &username, const QString &password) RegisterRequest::RegisterRequest(const QString &username, const QString &password)

View file

@ -15,13 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "RegisterPage.h"
#include "Avatar.h" #include "Avatar.h"
#include "Config.h" #include "Config.h"
#include "FlatButton.h" #include "FlatButton.h"
#include "InputValidator.h" #include "InputValidator.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "RaisedButton.h" #include "RaisedButton.h"
#include "RegisterPage.h"
#include "TextField.h" #include "TextField.h"
RegisterPage::RegisterPage(QSharedPointer<MatrixClient> client, QWidget *parent) RegisterPage::RegisterPage(QSharedPointer<MatrixClient> client, QWidget *parent)