summary refs log tree commit diff
path: root/src/ui/UserProfile.cpp
diff options
context:
space:
mode:
authorJedi18 <targetakhil@gmail.com>2021-01-28 20:03:50 +0530
committerJedi18 <targetakhil@gmail.com>2021-01-28 20:03:50 +0530
commit87490c29cd8af7c17b5a4591798f1f0ebfa9023c (patch)
treec50314997fdebd69b54464dd7ee55c41f9cc5419 /src/ui/UserProfile.cpp
parentupdate room specific username from userprofile (diff)
downloadnheko-87490c29cd8af7c17b5a4591798f1f0ebfa9023c.tar.xz
Username can be edited by double clicking on text, added global user profile menu action in user info widget
Diffstat (limited to 'src/ui/UserProfile.cpp')
-rw-r--r--src/ui/UserProfile.cpp83
1 files changed, 50 insertions, 33 deletions
diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp

index 503f314c..4b7f054d 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp
@@ -108,6 +108,12 @@ UserProfile::avatarUrl() } bool +UserProfile::globalUserProfile() const +{ + return (roomid_ == "") && isSelf(); +} + +bool UserProfile::getUserStatus() { return isUserVerified; @@ -217,39 +223,37 @@ UserProfile::startChat() void UserProfile::changeUsername(QString username) { - // change room username - mtx::events::state::Member member; - member.display_name = username.toStdString(); - member.avatar_url = - cache::avatarUrl(roomid_, - QString::fromStdString(http::client()->user_id().to_string())) - .toStdString(); - member.membership = mtx::events::state::Membership::Join; - - http::client()->send_state_event(roomid_.toStdString(), - http::client()->user_id().to_string(), - member, - [](mtx::responses::EventId, mtx::http::RequestErr err) { - if (err) - nhlog::net()->error( - "Failed to set room displayname: {}", - err->matrix_error.error); - }); - - /*connect(modal, &EditModal::nameChanged, this, [this](const QString &newName) { - if (roomNameLabel_) - roomNameLabel_->setText(newName); - });*/ - - /*std::string newName = "jedi18"; - // change user name - http::client()->set_displayname( - newName, [this]( mtx::http::RequestErr err) { - if (err) { - nhlog::net()->warn("could not change username"); - return; - } - });*/ + if (globalUserProfile()) { + // change global + http::client()->set_displayname( + username.toStdString(), [this]( mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("could not change username"); + return; + } + }); + } else { + // change room username + mtx::events::state::Member member; + member.display_name = username.toStdString(); + member.avatar_url = + cache::avatarUrl(roomid_, + QString::fromStdString(http::client()->user_id().to_string())) + .toStdString(); + member.membership = mtx::events::state::Membership::Join; + + http::client()->send_state_event( + roomid_.toStdString(), + http::client()->user_id().to_string(), + member, + [](mtx::responses::EventId, mtx::http::RequestErr err) { + if (err) + nhlog::net()->error("Failed to set room displayname: {}", + err->matrix_error.error); + }); + } + + allowUsernameEditing(false); } void @@ -267,3 +271,16 @@ UserProfile::unverify(QString device) { cache::markDeviceUnverified(userid_.toStdString(), device.toStdString()); } + +void +UserProfile::allowUsernameEditing(bool allow) +{ + usernameEditing = allow; + emit usernameEditingChanged(); +} + +bool +UserProfile::isUsernameEditingAllowed() const +{ + return usernameEditing; +}