Display user avatar changes

remotes/origin/HEAD
Konstantinos Sideris 7 years ago
parent c18a49915b
commit e224440f5d
  1. 12
      include/AvatarProvider.h
  2. 42
      src/AvatarProvider.cc
  3. 2
      src/EmojiPickButton.cc
  4. 2
      src/Login.cc
  5. 2
      src/LoginPage.cc
  6. 1
      src/Profile.cc
  7. 1
      src/Register.cc
  8. 2
      src/RegisterPage.cc

@ -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<MatrixClient> client_;
static QMap<QString, QList<TimelineItem *>> toBeResolved_;
static QMap<QString, QImage> userAvatars_;
static QMap<QString, QUrl> avatarUrls_;
using UserID = QString;
static QMap<UserID, AvatarData> avatars_;
static QMap<UserID, QList<TimelineItem *>> toBeResolved_;
};

@ -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,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;
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]);
// Add the current timeline item to the waiting list for this avatar.
if (!toBeResolved_.contains(userId)) {
client_->fetchUserAvatar(userId, avatars_[userId].url);
QList<TimelineItem *> timelineItems;
timelineItems.push_back(item);
QList<TimelineItem *> 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();
}

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

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

@ -15,11 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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"

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

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

@ -15,13 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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<MatrixClient> client, QWidget *parent)

Loading…
Cancel
Save