summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-08-13 16:28:41 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2022-08-13 16:28:41 +0200
commit242b7d55069ac50b4b139bf49ccc72577d6c2766 (patch)
tree8beb3d32d947f501768d1ee254c134175401da58 /src
parentEnable encryption for DMs when started from the profile (diff)
downloadnheko-242b7d55069ac50b4b139bf49ccc72577d6c2766.tar.xz
Fix crash when fetching global profile
Diffstat (limited to 'src')
-rw-r--r--src/MainWindow.cpp2
-rw-r--r--src/ui/UserProfile.cpp30
-rw-r--r--src/ui/UserProfile.h13
3 files changed, 35 insertions, 10 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp

index e5032fb2..5b850999 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp
@@ -67,6 +67,7 @@ Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents) Q_DECLARE_METATYPE(std::vector<DeviceInfo>) Q_DECLARE_METATYPE(std::vector<mtx::responses::PublicRoomsChunk>) Q_DECLARE_METATYPE(mtx::responses::PublicRoom) +Q_DECLARE_METATYPE(mtx::responses::Profile) MainWindow *MainWindow::instance_ = nullptr; @@ -145,6 +146,7 @@ MainWindow::registerQmlTypes() qRegisterMetaType<mtx::events::msg::KeyVerificationRequest>(); qRegisterMetaType<mtx::events::msg::KeyVerificationStart>(); qRegisterMetaType<mtx::responses::PublicRoom>(); + qRegisterMetaType<mtx::responses::Profile>(); qRegisterMetaType<CombinedImagePackModel *>(); qRegisterMetaType<mtx::events::collections::TimelineEvents>(); qRegisterMetaType<std::vector<DeviceInfo>>(); diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp
index d1559112..bd02b308 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp
@@ -487,17 +487,27 @@ UserProfile::isLoading() const 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 profile info for {}", userid_.toStdString()); - return; - } + auto profProx = std::make_shared<UserProfileFetchProxy>(); + connect(profProx.get(), + &UserProfileFetchProxy::profileFetched, + this, + [this](const mtx::responses::Profile &res) { + emit globalUsernameRetrieved(QString::fromStdString(res.display_name)); + globalAvatarUrl = QString::fromStdString(res.avatar_url); + emit avatarUrlChanged(); + }); - emit globalUsernameRetrieved(QString::fromStdString(res.display_name)); - globalAvatarUrl = QString::fromStdString(res.avatar_url); - emit avatarUrlChanged(); - }); + http::client()->get_profile(userid_.toStdString(), + [prox = std::move(profProx), user = userid_.toStdString()]( + const mtx::responses::Profile &res, mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to retrieve profile info for {}", + user); + return; + } + + emit prox->profileFetched(res); + }); } void diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h
index 4652a72e..0f94914d 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h
@@ -32,6 +32,19 @@ Q_ENUM_NS(Status) class DeviceVerificationFlow; class TimelineViewManager; +class UserProfileFetchProxy : public QObject +{ + Q_OBJECT + +public: + UserProfileFetchProxy(QObject *p = nullptr) + : QObject(p) + {} + +signals: + void profileFetched(mtx::responses::Profile); +}; + class DeviceInfo { public: