Show avatars in the completion popup
1 files changed, 12 insertions, 4 deletions
diff --git a/include/AvatarProvider.h b/include/AvatarProvider.h
index f3441290..95a5765d 100644
--- a/include/AvatarProvider.h
+++ b/include/AvatarProvider.h
@@ -25,9 +25,12 @@
class MatrixClient;
class TimelineItem;
+//! Saved cache data per user.
struct AvatarData
{
+ //! The avatar image of the user.
QImage img;
+ //! The url that was used to download the avatar.
QUrl url;
};
@@ -37,17 +40,22 @@ class AvatarProvider : public QObject
public:
static void init(QSharedPointer<MatrixClient> client);
- static void resolve(const QString &userId, std::function<void(QImage)> callback);
+ //! The callback is called with the downloaded avatar for the given user
+ //! or the avatar is downloaded first and then saved for re-use.
+ static void resolve(const QString &userId,
+ QObject *receiver,
+ std::function<void(QImage)> callback);
+ //! Used to initialize the mapping user -> avatar url.
static void setAvatarUrl(const QString &userId, const QUrl &url);
-
- static void clear();
+ //! Remove all saved data.
+ static void clear() { avatars_.clear(); };
private:
+ //! Update the cache with the downloaded avatar.
static void updateAvatar(const QString &uid, const QImage &img);
static QSharedPointer<MatrixClient> client_;
using UserID = QString;
static std::map<UserID, AvatarData> avatars_;
- static std::map<UserID, std::vector<std::function<void(QImage)>>> toBeResolved_;
};
|