|
|
|
@ -21,8 +21,7 @@ |
|
|
|
|
|
|
|
|
|
QSharedPointer<MatrixClient> AvatarProvider::client_; |
|
|
|
|
|
|
|
|
|
QMap<QString, QImage> AvatarProvider::userAvatars_; |
|
|
|
|
QMap<QString, QUrl> AvatarProvider::avatarUrls_; |
|
|
|
|
QMap<QString, AvatarData> AvatarProvider::avatars_; |
|
|
|
|
QMap<QString, QList<TimelineItem *>> AvatarProvider::toBeResolved_; |
|
|
|
|
|
|
|
|
|
void |
|
|
|
@ -46,24 +45,28 @@ 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; |
|
|
|
|
|
|
|
|
|
item->setUserAvatar(img); |
|
|
|
|
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]); |
|
|
|
|
client_->fetchUserAvatar(userId, avatars_[userId].url); |
|
|
|
|
|
|
|
|
|
QList<TimelineItem *> timelineItems; |
|
|
|
|
timelineItems.push_back(item); |
|
|
|
@ -72,19 +75,20 @@ AvatarProvider::resolve(const QString &userId, TimelineItem *item) |
|
|
|
|
} 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(); |
|
|
|
|
} |
|
|
|
|