summary refs log tree commit diff
path: root/src/ui/UserProfile.cpp
diff options
context:
space:
mode:
authorJoseph Donofry <joedonofry@gmail.com>2021-02-01 18:42:38 -0500
committerJoseph Donofry <joedonofry@gmail.com>2021-02-01 18:42:38 -0500
commit53c653a228f529bab3753ca99dee18a5bf5342a2 (patch)
treead0ba40d27ca5a515f1f33c29c910e5cf7b20dd7 /src/ui/UserProfile.cpp
parentRemove redundant import and fix visible warning (diff)
parentFix emojis with fe0f in the middle (diff)
downloadnheko-53c653a228f529bab3753ca99dee18a5bf5342a2.tar.xz
Merge remote-tracking branch 'nheko-im/master' into privacy_screen
Diffstat (limited to 'src/ui/UserProfile.cpp')
-rw-r--r--src/ui/UserProfile.cpp68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp

index 08219a38..3872294a 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp
@@ -7,6 +7,8 @@ #include "mtx/responses/crypto.hpp" #include "timeline/TimelineModel.h" #include "timeline/TimelineViewManager.h" +#include <mtx/responses.hpp> +#include <mtx/responses/common.hpp> UserProfile::UserProfile(QString roomid, QString userid, @@ -44,6 +46,23 @@ UserProfile::UserProfile(QString roomid, } deviceList_.reset(deviceList_.deviceList_); }); + + connect(this, + &UserProfile::globalUsernameRetrieved, + this, + &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)); + }); } QHash<int, QByteArray> @@ -97,7 +116,7 @@ UserProfile::userid() QString UserProfile::displayName() { - return cache::displayName(roomid_, userid_); + return isGlobalUserProfile() ? globalUsername : cache::displayName(roomid_, userid_); } QString @@ -107,6 +126,12 @@ UserProfile::avatarUrl() } bool +UserProfile::isGlobalUserProfile() const +{ + return roomid_ == ""; +} + +bool UserProfile::getUserStatus() { return isUserVerified; @@ -214,6 +239,40 @@ UserProfile::startChat() } void +UserProfile::changeUsername(QString username) +{ + if (isGlobalUserProfile()) { + // 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); + }); + } +} + +void UserProfile::verify(QString device) { if (!device.isEmpty()) @@ -228,3 +287,10 @@ UserProfile::unverify(QString device) { cache::markDeviceUnverified(userid_.toStdString(), device.toStdString()); } + +void +UserProfile::setGlobalUsername(const QString &globalUser) +{ + globalUsername = globalUser; + emit displayNameChanged(); +} \ No newline at end of file