From 5e3f5136557b83ee964d6c0cfa4fed422330728d Mon Sep 17 00:00:00 2001 From: Jedi18 Date: Wed, 27 Jan 2021 11:03:08 +0530 Subject: update room specific username from userprofile --- src/timeline/TimelineModel.cpp | 4 ++-- src/timeline/TimelineModel.h | 2 +- src/ui/UserProfile.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/ui/UserProfile.h | 1 + 4 files changed, 43 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 4346b0b2..79cf5184 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -799,9 +799,9 @@ TimelineModel::viewDecryptedRawMessage(QString id) const } void -TimelineModel::openUserProfile(QString userid) +TimelineModel::openUserProfile(QString userid, bool global) { - emit openProfile(new UserProfile(room_id_, userid, manager_, this)); + emit openProfile(new UserProfile(global ? "" : room_id_, userid, manager_, this)); } void diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 35e62eb4..51b8049e 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -212,7 +212,7 @@ public: Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void viewDecryptedRawMessage(QString id) const; - Q_INVOKABLE void openUserProfile(QString userid); + Q_INVOKABLE void openUserProfile(QString userid, bool global = false); Q_INVOKABLE void replyAction(QString id); Q_INVOKABLE void readReceiptsAction(QString id) const; Q_INVOKABLE void redactEvent(QString id); diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp index 08219a38..503f314c 100644 --- a/src/ui/UserProfile.cpp +++ b/src/ui/UserProfile.cpp @@ -4,6 +4,7 @@ #include "DeviceVerificationFlow.h" #include "Logging.h" #include "Utils.h" +#include #include "mtx/responses/crypto.hpp" #include "timeline/TimelineModel.h" #include "timeline/TimelineViewManager.h" @@ -213,6 +214,44 @@ UserProfile::startChat() ChatPage::instance()->startChat(this->userid_); } +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; + } + });*/ +} + void UserProfile::verify(QString device) { diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index 19527310..df90e5a1 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -109,6 +109,7 @@ public: // Q_INVOKABLE void ignoreUser(); Q_INVOKABLE void kickUser(); Q_INVOKABLE void startChat(); + Q_INVOKABLE void changeUsername(QString username); signals: void userStatusChanged(); -- cgit 1.5.1