diff --git a/resources/qml/UserProfile.qml b/resources/qml/UserProfile.qml index 0ced5498eeefb69acf3f050d798ea2d295ce6dfb..5e577099034921a602f8f23ab48379d9046ccb74 100644 --- a/resources/qml/UserProfile.qml +++ b/resources/qml/UserProfile.qml @@ -42,15 +42,23 @@ ApplicationWindow { color: TimelineManager.userColor(profile.userid, colors.window) font.bold: true Layout.alignment: Qt.AlignHCenter - focus: true + selectByMouse: true - onEditingFinished: profile.changeUsername(displayUsername.text) + Keys.priority: Keys.BeforeItem + Keys.onReturnPressed: profile.changeUsername(displayUsername.text) - MouseArea { - enabled: !profile.isUsernameEditingAllowed - anchors.fill: parent - onDoubleClicked: { - profile.allowUsernameEditing(true) + ImageButton { + anchors.leftMargin: 5 + anchors.left: displayUsername.right + anchors.verticalCenter: displayUsername.verticalCenter + image: profile.isUsernameEditingAllowed ? ":/icons/icons/ui/checkmark.png" : ":/icons/icons/ui/edit.png" + + onClicked: { + if(profile.isUsernameEditingAllowed) { + profile.changeUsername(displayUsername.text) + }else{ + profile.allowUsernameEditing(true) + } } } } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index ffb0beec58313952efc222e8b00d99c6b0b87749..41c0b40ed8571e15473f5cf462461fb7b199c20f 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -22,6 +22,7 @@ #include "TimelineViewManager.h" #include "Utils.h" #include "dialogs/RawMessage.h" +#include <mtx/responses.hpp> Q_DECLARE_METATYPE(QModelIndex) @@ -260,6 +261,17 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) { this->updateFlowEventId(event_id); }); + + const auto userid = utils::localUser().toStdString(); + http::client()->get_profile( + userid, [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to retrieve own profile info"); + return; + } + + globalUsername = QString::fromStdString(res.display_name); + }); } QHash<int, QByteArray> @@ -801,7 +813,12 @@ TimelineModel::viewDecryptedRawMessage(QString id) const void TimelineModel::openUserProfile(QString userid, bool global) { - emit openProfile(new UserProfile(global ? "" : room_id_, global ? utils::localUser() : userid, manager_, this)); + if (global) { + emit openProfile(new UserProfile("",utils::localUser(), + manager_, this, globalUsername)); + } else { + emit openProfile(new UserProfile(room_id_, userid, manager_, this)); + } } void diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 51b8049e07beb8fde927109dbac7d51150df50c9..e6cb7d3ab3e19fae34e0b96a0c078ee8c2339d9b 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -317,6 +317,7 @@ private: mutable EventStore events; QString room_id_; + QString globalUsername; bool decryptDescription = true; bool m_paginationInProgress = false; diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 4b7f054d307d2e544c6b501d029c9b1132311018..a53d25f404d1a38250334c72274f3458a4901aaa 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -12,12 +12,14 @@ UserProfile::UserProfile(QString roomid, QString userid, TimelineViewManager *manager_, - TimelineModel *parent) + TimelineModel *parent, + QString globalUsername) : QObject(parent) , roomid_(roomid) , userid_(userid) , manager(manager_) , model(parent) + , globalUsername(globalUsername) { fetchDeviceList(this->userid_); @@ -98,7 +100,7 @@ UserProfile::userid() QString UserProfile::displayName() { - return cache::displayName(roomid_, userid_); + return globalUserProfile() ? globalUsername : cache::displayName(roomid_, userid_); } QString diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index 4839e0d88e1ea60b7829eda343eef2b8798eb58a..04317766e58fdb82e9ffc2faf3d575af82b99669 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -94,7 +94,8 @@ public: UserProfile(QString roomid, QString userid, TimelineViewManager *manager_, - TimelineModel *parent = nullptr); + TimelineModel *parent = nullptr, + QString globalUsername = ""); DeviceInfoModel *deviceList(); @@ -119,11 +120,11 @@ public: signals: void userStatusChanged(); - void usernameEditingChanged(); private: QString roomid_, userid_; + QString globalUsername; DeviceInfoModel deviceList_; bool isUserVerified = false; bool hasMasterKey = false;