From 567fe81ad78e707a4b914976a92c855d4ac8fc45 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 14 May 2021 23:35:34 +0200 Subject: Basic header and footer of room list --- src/ui/UserProfile.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/ui/UserProfile.cpp') diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 0f330964..cef8bd85 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -27,9 +27,22 @@ UserProfile::UserProfile(QString roomid, , manager(manager_) , model(parent) { - fetchDeviceList(this->userid_); globalAvatarUrl = ""; + connect(this, + &UserProfile::globalUsernameRetrieved, + this, + &UserProfile::setGlobalUsername, + Qt::QueuedConnection); + + if (isGlobalUserProfile()) { + getGlobalProfileData(); + } + + if (!cache::client() || !cache::client()->isDatabaseReady()) + return; + + fetchDeviceList(this->userid_); connect(cache::client(), &Cache::verificationStatusChanged, this, @@ -54,16 +67,6 @@ UserProfile::UserProfile(QString roomid, } deviceList_.reset(deviceList_.deviceList_); }); - - connect(this, - &UserProfile::globalUsernameRetrieved, - this, - &UserProfile::setGlobalUsername, - Qt::QueuedConnection); - - if (isGlobalUserProfile()) { - getGlobalProfileData(); - } } QHash @@ -157,6 +160,9 @@ UserProfile::fetchDeviceList(const QString &userID) { auto localUser = utils::localUser(); + if (!cache::client() || !cache::client()->isDatabaseReady()) + return; + cache::client()->query_keys( userID.toStdString(), [other_user_id = userID.toStdString(), this](const UserKeyCache &other_user_keys, -- cgit 1.5.1 From f2bc1845508cc2d90540404b6b9e11192cc56104 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 22 May 2021 14:31:38 +0200 Subject: Fix device list not showing up and UserProfile blocking the window --- resources/qml/RoomList.qml | 10 +++++++ resources/qml/RoomSettings.qml | 4 +-- resources/qml/UserProfile.qml | 2 +- .../qml/device-verification/DeviceVerification.qml | 2 +- src/Cache.cpp | 32 ++++++++++------------ src/ui/NhekoGlobalObject.h | 2 +- src/ui/UserProfile.cpp | 4 ++- src/ui/UserProfile.h | 3 +- 8 files changed, 35 insertions(+), 24 deletions(-) (limited to 'src/ui/UserProfile.cpp') diff --git a/resources/qml/RoomList.qml b/resources/qml/RoomList.qml index 979e727d..cde744c5 100644 --- a/resources/qml/RoomList.qml +++ b/resources/qml/RoomList.qml @@ -212,6 +212,16 @@ Page { Layout.preferredHeight: userInfoGrid.implicitHeight + 2 * Nheko.paddingMedium Layout.minimumHeight: 40 + TapHandler { + onSingleTapped: { + Nheko.updateUserProfile(); + var userProfile = userProfileComponent.createObject(timelineRoot, { + "profile": Nheko.currentUser + }); + userProfile.show(); + } + } + RowLayout { id: userInfoGrid diff --git a/resources/qml/RoomSettings.qml b/resources/qml/RoomSettings.qml index 14de0edf..1f7fe5de 100644 --- a/resources/qml/RoomSettings.qml +++ b/resources/qml/RoomSettings.qml @@ -20,7 +20,7 @@ ApplicationWindow { minimumHeight: 650 palette: Nheko.colors color: Nheko.colors.window - modality: Qt.WindowModal + modality: Qt.NonModal flags: Qt.Dialog title: qsTr("Room Settings") @@ -205,7 +205,7 @@ ApplicationWindow { title: qsTr("End-to-End Encryption") text: qsTr("Encryption is currently experimental and things might break unexpectedly.
Please take note that it can't be disabled afterwards.") - modality: Qt.WindowModal + modality: Qt.NonModal onAccepted: { if (roomSettings.isEncryptionEnabled) return ; diff --git a/resources/qml/UserProfile.qml b/resources/qml/UserProfile.qml index 4e5e64dc..21f34f15 100644 --- a/resources/qml/UserProfile.qml +++ b/resources/qml/UserProfile.qml @@ -22,7 +22,7 @@ ApplicationWindow { palette: Nheko.colors color: Nheko.colors.window title: profile.isGlobalUserProfile ? qsTr("Global User Profile") : qsTr("Room User Profile") - modality: Qt.WindowModal + modality: Qt.NonModal flags: Qt.Dialog Shortcut { diff --git a/resources/qml/device-verification/DeviceVerification.qml b/resources/qml/device-verification/DeviceVerification.qml index 6d0be204..e2c66c5a 100644 --- a/resources/qml/device-verification/DeviceVerification.qml +++ b/resources/qml/device-verification/DeviceVerification.qml @@ -15,7 +15,7 @@ ApplicationWindow { onClosing: TimelineManager.removeVerificationFlow(flow) title: stack.currentItem.title flags: Qt.Dialog - modality: Qt.WindowModal + modality: Qt.NonModal palette: Nheko.colors height: stack.implicitHeight width: stack.implicitWidth diff --git a/src/Cache.cpp b/src/Cache.cpp index d8c78381..c41b66cc 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -3469,6 +3469,7 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query } } } + for (auto &[user_id, update] : updates) { (void)update; if (user_id == local_user) { @@ -3476,9 +3477,8 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query (void)status; emit verificationStatusChanged(user); } - } else { - emit verificationStatusChanged(user_id); } + emit verificationStatusChanged(user_id); } } @@ -3552,6 +3552,19 @@ Cache::query_keys(const std::string &user_id, last_changed = cache_->last_changed; req.token = last_changed; + // use context object so that we can disconnect again + QObject *context{new QObject(this)}; + QObject::connect(this, + &Cache::verificationStatusChanged, + context, + [cb, user_id, context_ = context](std::string updated_user) mutable { + if (user_id == updated_user) { + context_->deleteLater(); + auto keys = cache::userKeys(user_id); + cb(keys.value_or(UserKeyCache{}), {}); + } + }); + http::client()->query_keys( req, [cb, user_id, last_changed, this](const mtx::responses::QueryKeys &res, @@ -3565,21 +3578,6 @@ Cache::query_keys(const std::string &user_id, } emit userKeysUpdate(last_changed, res); - - // use context object so that we can disconnect again - std::unique_ptr context{new QObject}; - QObject *pcontext = context.get(); - QObject::connect( - this, - &Cache::verificationStatusChanged, - pcontext, - [cb, user_id, context_ = std::move(context)](std::string updated_user) mutable { - if (user_id == updated_user) { - context_.release(); - auto keys = cache::userKeys(user_id); - cb(keys.value_or(UserKeyCache{}), {}); - } - }); }); } diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h index fe645a34..fc35fe22 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h @@ -40,7 +40,7 @@ public: Q_INVOKABLE void openLink(QString link) const; -private slots: +public slots: void updateUserProfile(); signals: diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index cef8bd85..da130242 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -42,7 +42,6 @@ UserProfile::UserProfile(QString roomid, if (!cache::client() || !cache::client()->isDatabaseReady()) return; - fetchDeviceList(this->userid_); connect(cache::client(), &Cache::verificationStatusChanged, this, @@ -66,7 +65,9 @@ UserProfile::UserProfile(QString roomid, : verification::VERIFIED; } deviceList_.reset(deviceList_.deviceList_); + emit devicesChanged(); }); + fetchDeviceList(this->userid_); } QHash @@ -223,6 +224,7 @@ UserProfile::fetchDeviceList(const QString &userID) } this->deviceList_.queueReset(std::move(deviceInfo)); + emit devicesChanged(); }); }); } diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index bf71d0de..721d7230 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -90,7 +90,7 @@ class UserProfile : public QObject Q_PROPERTY(QString displayName READ displayName NOTIFY displayNameChanged) Q_PROPERTY(QString userid READ userid CONSTANT) Q_PROPERTY(QString avatarUrl READ avatarUrl NOTIFY avatarUrlChanged) - Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT) + Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList NOTIFY devicesChanged) Q_PROPERTY(bool isGlobalUserProfile READ isGlobalUserProfile CONSTANT) Q_PROPERTY(int userVerified READ getUserStatus NOTIFY userStatusChanged) Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged) @@ -133,6 +133,7 @@ signals: void avatarUrlChanged(); void displayError(const QString &errorMessage); void globalUsernameRetrieved(const QString &globalUser); + void devicesChanged(); public slots: void updateAvatarUrl(); -- cgit 1.5.1 From e6878ee298525ac7808595418c4b84b93788ff2e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 12 Jun 2021 16:05:45 +0200 Subject: Don't read avatarUrl from local profile, if no global avatar is set --- resources/qml/RoomList.qml | 12 +++++++----- src/Cache.cpp | 3 ++- src/ui/UserProfile.cpp | 8 +++----- 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src/ui/UserProfile.cpp') diff --git a/resources/qml/RoomList.qml b/resources/qml/RoomList.qml index 09fb3701..f31fce60 100644 --- a/resources/qml/RoomList.qml +++ b/resources/qml/RoomList.qml @@ -447,6 +447,8 @@ Page { RowLayout { id: userInfoGrid + property var profile: Nheko.currentUser + spacing: Nheko.paddingMedium anchors.fill: parent anchors.margins: Nheko.paddingMedium @@ -457,9 +459,9 @@ Page { Layout.alignment: Qt.AlignVCenter Layout.preferredWidth: fontMetrics.lineSpacing * 2 Layout.preferredHeight: fontMetrics.lineSpacing * 2 - url: Nheko.currentUser.avatarUrl.replace("mxc://", "image://MxcImage/") - displayName: Nheko.currentUser.displayName - userid: Nheko.currentUser.userid + url: (userInfoGrid.profile ? userInfoGrid.profile.avatarUrl : "").replace("mxc://", "image://MxcImage/") + displayName: userInfoGrid.profile ? userInfoGrid.profile.displayName : "" + userid: userInfoGrid.profile ? userInfoGrid.profile.userid : "" } ColumnLayout { @@ -476,7 +478,7 @@ Page { Layout.alignment: Qt.AlignBottom font.pointSize: fontMetrics.font.pointSize * 1.1 font.weight: Font.DemiBold - fullText: Nheko.currentUser.displayName + fullText: userInfoGrid.profile ? userInfoGrid.profile.displayName : "" elideWidth: col.width } @@ -486,7 +488,7 @@ Page { font.weight: Font.Thin font.pointSize: fontMetrics.font.pointSize * 0.9 elideWidth: col.width - fullText: Nheko.currentUser.userid + fullText: userInfoGrid.profile ? userInfoGrid.profile.userid : "" } } diff --git a/src/Cache.cpp b/src/Cache.cpp index 5684de37..0d75ac51 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -2479,7 +2479,8 @@ Cache::getMember(const std::string &room_id, const std::string &user_id) return m; } } catch (std::exception &e) { - nhlog::db()->warn("Failed to read member ({}): {}", user_id, e.what()); + nhlog::db()->warn( + "Failed to read member ({}) in room ({}): {}", user_id, room_id, e.what()); } return std::nullopt; } diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index da130242..3d9c4b6a 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -39,7 +39,8 @@ UserProfile::UserProfile(QString roomid, getGlobalProfileData(); } - if (!cache::client() || !cache::client()->isDatabaseReady()) + if (!cache::client() || !cache::client()->isDatabaseReady() || + !ChatPage::instance()->timelineManager()) return; connect(cache::client(), @@ -127,10 +128,7 @@ UserProfile::displayName() QString UserProfile::avatarUrl() { - return (isGlobalUserProfile() && globalAvatarUrl != "") - ? globalAvatarUrl - : cache::avatarUrl(roomid_, userid_); - ; + return isGlobalUserProfile() ? globalAvatarUrl : cache::avatarUrl(roomid_, userid_); } bool -- cgit 1.5.1