summary refs log tree commit diff
path: root/src
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
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')
-rw-r--r--src/ChatPage.cpp4
-rw-r--r--src/UserInfoWidget.cpp4
-rw-r--r--src/UserInfoWidget.h3
-rw-r--r--src/timeline/TimelineModel.cpp2
-rw-r--r--src/ui/UserProfile.cpp83
-rw-r--r--src/ui/UserProfile.h9
6 files changed, 71 insertions, 34 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp

index 4e472a3a..0d3c98a8 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp
@@ -112,6 +112,10 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) connect(sidebarActions_, &SideBarActions::createRoom, this, &ChatPage::createRoom); user_info_widget_ = new UserInfoWidget(sideBar_); + connect(user_info_widget_, &UserInfoWidget::openGlobalUserProfile, this, [this]() { + view_manager_->activeTimeline()->openUserProfile("", true); + }); + user_mentions_popup_ = new popups::UserMentions(); room_list_ = new RoomList(userSettings, sideBar_); connect(room_list_, &RoomList::joinRoom, this, &ChatPage::joinRoom); diff --git a/src/UserInfoWidget.cpp b/src/UserInfoWidget.cpp
index f8e94431..5bcb44a9 100644 --- a/src/UserInfoWidget.cpp +++ b/src/UserInfoWidget.cpp
@@ -125,6 +125,10 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) ChatPage::instance()->setStatus(text); }); + auto userProfileAction = menu->addAction(tr("User Profile Settings")); + connect( + userProfileAction, &QAction::triggered, this, [this]() { emit openGlobalUserProfile(); }); + #if 0 // disable presence menu until issues in synapse are resolved auto setAutoPresence = menu->addAction(tr("Set presence automatically")); connect(setAutoPresence, &QAction::triggered, this, []() { diff --git a/src/UserInfoWidget.h b/src/UserInfoWidget.h
index 03ab2cf0..bfcfbc0b 100644 --- a/src/UserInfoWidget.h +++ b/src/UserInfoWidget.h
@@ -51,6 +51,9 @@ protected: void paintEvent(QPaintEvent *event) override; void contextMenuEvent(QContextMenuEvent *) override; +signals: + void openGlobalUserProfile(); + private: Avatar *userAvatar_; diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 79cf5184..ffb0beec 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -801,7 +801,7 @@ TimelineModel::viewDecryptedRawMessage(QString id) const void TimelineModel::openUserProfile(QString userid, bool global) { - emit openProfile(new UserProfile(global ? "" : room_id_, userid, manager_, this)); + emit openProfile(new UserProfile(global ? "" : room_id_, global ? utils::localUser() : userid, manager_, this)); } void 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; +} diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h
index df90e5a1..4839e0d8 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h
@@ -83,10 +83,13 @@ class UserProfile : public QObject Q_PROPERTY(QString userid READ userid CONSTANT) Q_PROPERTY(QString avatarUrl READ avatarUrl CONSTANT) Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT) + Q_PROPERTY(bool globalUserProfile READ globalUserProfile CONSTANT) Q_PROPERTY(bool isUserVerified READ getUserStatus NOTIFY userStatusChanged) Q_PROPERTY( bool userVerificationEnabled READ userVerificationEnabled NOTIFY userStatusChanged) Q_PROPERTY(bool isSelf READ isSelf CONSTANT) + Q_PROPERTY( + bool isUsernameEditingAllowed READ isUsernameEditingAllowed NOTIFY usernameEditingChanged) public: UserProfile(QString roomid, QString userid, @@ -98,9 +101,11 @@ public: QString userid(); QString displayName(); QString avatarUrl(); + bool globalUserProfile() const; bool getUserStatus(); bool userVerificationEnabled() const; bool isSelf() const; + bool isUsernameEditingAllowed() const; Q_INVOKABLE void verify(QString device = ""); Q_INVOKABLE void unverify(QString device = ""); @@ -110,15 +115,19 @@ public: Q_INVOKABLE void kickUser(); Q_INVOKABLE void startChat(); Q_INVOKABLE void changeUsername(QString username); + Q_INVOKABLE void allowUsernameEditing(bool allow); signals: void userStatusChanged(); + void usernameEditingChanged(); + private: QString roomid_, userid_; DeviceInfoModel deviceList_; bool isUserVerified = false; bool hasMasterKey = false; + bool usernameEditing = false; TimelineViewManager *manager; TimelineModel *model; };