From 2ff3c0c97eda8f1503ee0c274c01566b34bc84f1 Mon Sep 17 00:00:00 2001 From: Jedi18 Date: Tue, 2 Feb 2021 17:46:02 +0530 Subject: [PATCH] fixed global avatar updation in the dialog --- src/ui/UserProfile.cpp | 37 ++++++++++++++++++++++++++----------- src/ui/UserProfile.h | 2 ++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index a3715fee..715c1c42 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -24,6 +24,7 @@ UserProfile::UserProfile(QString roomid, , model(parent) { fetchDeviceList(this->userid_); + globalAvatarUrl = ""; connect(cache::client(), &Cache::verificationStatusChanged, @@ -56,16 +57,9 @@ UserProfile::UserProfile(QString roomid, &UserProfile::setGlobalUsername, Qt::QueuedConnection); - http::client()->get_profile( - userid_.toStdString(), - [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) { - if (err) { - nhlog::net()->warn("failed to retrieve own profile info"); - return; - } - - emit globalUsernameRetrieved(QString::fromStdString(res.display_name)); - }); + if (isGlobalUserProfile()) { + getGlobalProfileData(); + } } QHash @@ -125,7 +119,10 @@ UserProfile::displayName() QString UserProfile::avatarUrl() { - return cache::avatarUrl(roomid_, userid_); + return (isGlobalUserProfile() && globalAvatarUrl != "") + ? globalAvatarUrl + : cache::avatarUrl(roomid_, userid_); + ; } bool @@ -353,6 +350,7 @@ UserProfile::changeAvatar() isLoading_ = false; emit loadingChanged(); + getGlobalProfileData(); }); } else { // change room username @@ -393,4 +391,21 @@ bool UserProfile::isLoading() const { return isLoading_; +} + +void +UserProfile::getGlobalProfileData() +{ + http::client()->get_profile( + userid_.toStdString(), + [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to retrieve own profile info"); + return; + } + + emit globalUsernameRetrieved(QString::fromStdString(res.display_name)); + globalAvatarUrl = QString::fromStdString(res.avatar_url); + emit avatarUrlChanged(); + }); } \ No newline at end of file diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index 58fb0f0b..ffc5dcae 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -134,10 +134,12 @@ protected slots: private: void updateRoomMemberState(mtx::events::state::Member member); + void getGlobalProfileData(); private: QString roomid_, userid_; QString globalUsername; + QString globalAvatarUrl; DeviceInfoModel deviceList_; bool isUserVerified = false; bool hasMasterKey = false;