mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-23 03:18:49 +03:00
update room specific username from userprofile
This commit is contained in:
parent
e6dc1da22f
commit
5e3f513655
5 changed files with 77 additions and 3 deletions
|
@ -58,6 +58,40 @@ ApplicationWindow {
|
||||||
onClicked: profile.verify()
|
onClicked: profile.verify()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: changeUsername
|
||||||
|
|
||||||
|
text: (profile.roomid_ == "") ? qsTr("Change global username") : qsTr("Change room username")
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
enabled : profile.isSelf
|
||||||
|
visible: profile.isSelf
|
||||||
|
onClicked: changeUsernameDialog.open()
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: changeUsernameDialog
|
||||||
|
modal: true
|
||||||
|
title: (profile.roomid_ == "") ? qsTr("Change global username") : qsTr("Change room username")
|
||||||
|
onAccepted: profile.changeUsername(usernameEdit.text)
|
||||||
|
|
||||||
|
Column {
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: "New Username"
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
TextField {
|
||||||
|
id: usernameEdit
|
||||||
|
focus: true
|
||||||
|
wrapMode: TextEdit.Wrap
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
standardButtons: Dialog.Ok | Dialog.Cancel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
Layout.preferredHeight: 16
|
Layout.preferredHeight: 16
|
||||||
Layout.preferredWidth: 16
|
Layout.preferredWidth: 16
|
||||||
|
|
|
@ -799,9 +799,9 @@ TimelineModel::viewDecryptedRawMessage(QString id) const
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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
|
void
|
||||||
|
|
|
@ -212,7 +212,7 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE void viewRawMessage(QString id) const;
|
Q_INVOKABLE void viewRawMessage(QString id) const;
|
||||||
Q_INVOKABLE void viewDecryptedRawMessage(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 replyAction(QString id);
|
||||||
Q_INVOKABLE void readReceiptsAction(QString id) const;
|
Q_INVOKABLE void readReceiptsAction(QString id) const;
|
||||||
Q_INVOKABLE void redactEvent(QString id);
|
Q_INVOKABLE void redactEvent(QString id);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "DeviceVerificationFlow.h"
|
#include "DeviceVerificationFlow.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
#include <mtx/responses/common.hpp>
|
||||||
#include "mtx/responses/crypto.hpp"
|
#include "mtx/responses/crypto.hpp"
|
||||||
#include "timeline/TimelineModel.h"
|
#include "timeline/TimelineModel.h"
|
||||||
#include "timeline/TimelineViewManager.h"
|
#include "timeline/TimelineViewManager.h"
|
||||||
|
@ -213,6 +214,44 @@ UserProfile::startChat()
|
||||||
ChatPage::instance()->startChat(this->userid_);
|
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
|
void
|
||||||
UserProfile::verify(QString device)
|
UserProfile::verify(QString device)
|
||||||
{
|
{
|
||||||
|
|
|
@ -109,6 +109,7 @@ public:
|
||||||
// Q_INVOKABLE void ignoreUser();
|
// Q_INVOKABLE void ignoreUser();
|
||||||
Q_INVOKABLE void kickUser();
|
Q_INVOKABLE void kickUser();
|
||||||
Q_INVOKABLE void startChat();
|
Q_INVOKABLE void startChat();
|
||||||
|
Q_INVOKABLE void changeUsername(QString username);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void userStatusChanged();
|
void userStatusChanged();
|
||||||
|
|
Loading…
Reference in a new issue