mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Display user avatar changes
This commit is contained in:
parent
c18a49915b
commit
e224440f5d
8 changed files with 38 additions and 26 deletions
|
@ -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_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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,45 +45,50 @@ 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, avatars_[userId].url);
|
||||||
client_->fetchUserAvatar(userId, avatarUrls_[userId]);
|
|
||||||
|
|
||||||
QList<TimelineItem *> timelineItems;
|
QList<TimelineItem *> timelineItems;
|
||||||
timelineItems.push_back(item);
|
timelineItems.push_back(item);
|
||||||
|
|
||||||
toBeResolved_.insert(userId, timelineItems);
|
toBeResolved_.insert(userId, timelineItems);
|
||||||
} else {
|
} else {
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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() {}
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Deserializable.h"
|
#include "Deserializable.h"
|
||||||
|
|
||||||
#include "Profile.h"
|
#include "Profile.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue