mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 14:18:49 +03:00
Username can be edited by double clicking on text, added global user profile menu action in user info widget
This commit is contained in:
parent
5e3f513655
commit
87490c29cd
7 changed files with 84 additions and 68 deletions
|
@ -15,6 +15,7 @@ ApplicationWindow {
|
||||||
minimumHeight: 420
|
minimumHeight: 420
|
||||||
palette: colors
|
palette: colors
|
||||||
color: colors.window
|
color: colors.window
|
||||||
|
title: profile.globalUserProfile ? "Global User Profile" : "Room User Profile"
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: contentL
|
id: contentL
|
||||||
|
@ -33,13 +34,25 @@ ApplicationWindow {
|
||||||
onClicked: TimelineManager.openImageOverlay(TimelineManager.timeline.avatarUrl(userid), TimelineManager.timeline.data.id)
|
onClicked: TimelineManager.openImageOverlay(TimelineManager.timeline.avatarUrl(userid), TimelineManager.timeline.data.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
TextInput {
|
||||||
|
id: displayUsername
|
||||||
|
readOnly: !profile.isUsernameEditingAllowed
|
||||||
text: profile.displayName
|
text: profile.displayName
|
||||||
fontSizeMode: Text.HorizontalFit
|
|
||||||
font.pixelSize: 20
|
font.pixelSize: 20
|
||||||
color: TimelineManager.userColor(profile.userid, colors.window)
|
color: TimelineManager.userColor(profile.userid, colors.window)
|
||||||
font.bold: true
|
font.bold: true
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
focus: true
|
||||||
|
|
||||||
|
onEditingFinished: profile.changeUsername(displayUsername.text)
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
enabled: !profile.isUsernameEditingAllowed
|
||||||
|
anchors.fill: parent
|
||||||
|
onDoubleClicked: {
|
||||||
|
profile.allowUsernameEditing(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixText {
|
MatrixText {
|
||||||
|
@ -58,40 +71,6 @@ 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
|
||||||
|
|
|
@ -112,6 +112,10 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
||||||
connect(sidebarActions_, &SideBarActions::createRoom, this, &ChatPage::createRoom);
|
connect(sidebarActions_, &SideBarActions::createRoom, this, &ChatPage::createRoom);
|
||||||
|
|
||||||
user_info_widget_ = new UserInfoWidget(sideBar_);
|
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();
|
user_mentions_popup_ = new popups::UserMentions();
|
||||||
room_list_ = new RoomList(userSettings, sideBar_);
|
room_list_ = new RoomList(userSettings, sideBar_);
|
||||||
connect(room_list_, &RoomList::joinRoom, this, &ChatPage::joinRoom);
|
connect(room_list_, &RoomList::joinRoom, this, &ChatPage::joinRoom);
|
||||||
|
|
|
@ -125,6 +125,10 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
|
||||||
ChatPage::instance()->setStatus(text);
|
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
|
#if 0 // disable presence menu until issues in synapse are resolved
|
||||||
auto setAutoPresence = menu->addAction(tr("Set presence automatically"));
|
auto setAutoPresence = menu->addAction(tr("Set presence automatically"));
|
||||||
connect(setAutoPresence, &QAction::triggered, this, []() {
|
connect(setAutoPresence, &QAction::triggered, this, []() {
|
||||||
|
|
|
@ -51,6 +51,9 @@ protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
void contextMenuEvent(QContextMenuEvent *) override;
|
void contextMenuEvent(QContextMenuEvent *) override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void openGlobalUserProfile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Avatar *userAvatar_;
|
Avatar *userAvatar_;
|
||||||
|
|
||||||
|
|
|
@ -801,7 +801,7 @@ TimelineModel::viewDecryptedRawMessage(QString id) const
|
||||||
void
|
void
|
||||||
TimelineModel::openUserProfile(QString userid, bool global)
|
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
|
void
|
||||||
|
|
|
@ -107,6 +107,12 @@ UserProfile::avatarUrl()
|
||||||
return cache::avatarUrl(roomid_, userid_);
|
return cache::avatarUrl(roomid_, userid_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
UserProfile::globalUserProfile() const
|
||||||
|
{
|
||||||
|
return (roomid_ == "") && isSelf();
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
UserProfile::getUserStatus()
|
UserProfile::getUserStatus()
|
||||||
{
|
{
|
||||||
|
@ -217,39 +223,37 @@ UserProfile::startChat()
|
||||||
void
|
void
|
||||||
UserProfile::changeUsername(QString username)
|
UserProfile::changeUsername(QString username)
|
||||||
{
|
{
|
||||||
// change room username
|
if (globalUserProfile()) {
|
||||||
mtx::events::state::Member member;
|
// change global
|
||||||
member.display_name = username.toStdString();
|
http::client()->set_displayname(
|
||||||
member.avatar_url =
|
username.toStdString(), [this]( mtx::http::RequestErr err) {
|
||||||
cache::avatarUrl(roomid_,
|
if (err) {
|
||||||
QString::fromStdString(http::client()->user_id().to_string()))
|
nhlog::net()->warn("could not change username");
|
||||||
.toStdString();
|
return;
|
||||||
member.membership = mtx::events::state::Membership::Join;
|
}
|
||||||
|
});
|
||||||
|
} 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()->send_state_event(
|
||||||
http::client()->user_id().to_string(),
|
roomid_.toStdString(),
|
||||||
member,
|
http::client()->user_id().to_string(),
|
||||||
[](mtx::responses::EventId, mtx::http::RequestErr err) {
|
member,
|
||||||
if (err)
|
[](mtx::responses::EventId, mtx::http::RequestErr err) {
|
||||||
nhlog::net()->error(
|
if (err)
|
||||||
"Failed to set room displayname: {}",
|
nhlog::net()->error("Failed to set room displayname: {}",
|
||||||
err->matrix_error.error);
|
err->matrix_error.error);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/*connect(modal, &EditModal::nameChanged, this, [this](const QString &newName) {
|
allowUsernameEditing(false);
|
||||||
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
|
||||||
|
@ -267,3 +271,16 @@ UserProfile::unverify(QString device)
|
||||||
{
|
{
|
||||||
cache::markDeviceUnverified(userid_.toStdString(), device.toStdString());
|
cache::markDeviceUnverified(userid_.toStdString(), device.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserProfile::allowUsernameEditing(bool allow)
|
||||||
|
{
|
||||||
|
usernameEditing = allow;
|
||||||
|
emit usernameEditingChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
UserProfile::isUsernameEditingAllowed() const
|
||||||
|
{
|
||||||
|
return usernameEditing;
|
||||||
|
}
|
||||||
|
|
|
@ -83,10 +83,13 @@ class UserProfile : public QObject
|
||||||
Q_PROPERTY(QString userid READ userid CONSTANT)
|
Q_PROPERTY(QString userid READ userid CONSTANT)
|
||||||
Q_PROPERTY(QString avatarUrl READ avatarUrl CONSTANT)
|
Q_PROPERTY(QString avatarUrl READ avatarUrl CONSTANT)
|
||||||
Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList 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 isUserVerified READ getUserStatus NOTIFY userStatusChanged)
|
||||||
Q_PROPERTY(
|
Q_PROPERTY(
|
||||||
bool userVerificationEnabled READ userVerificationEnabled NOTIFY userStatusChanged)
|
bool userVerificationEnabled READ userVerificationEnabled NOTIFY userStatusChanged)
|
||||||
Q_PROPERTY(bool isSelf READ isSelf CONSTANT)
|
Q_PROPERTY(bool isSelf READ isSelf CONSTANT)
|
||||||
|
Q_PROPERTY(
|
||||||
|
bool isUsernameEditingAllowed READ isUsernameEditingAllowed NOTIFY usernameEditingChanged)
|
||||||
public:
|
public:
|
||||||
UserProfile(QString roomid,
|
UserProfile(QString roomid,
|
||||||
QString userid,
|
QString userid,
|
||||||
|
@ -98,9 +101,11 @@ public:
|
||||||
QString userid();
|
QString userid();
|
||||||
QString displayName();
|
QString displayName();
|
||||||
QString avatarUrl();
|
QString avatarUrl();
|
||||||
|
bool globalUserProfile() const;
|
||||||
bool getUserStatus();
|
bool getUserStatus();
|
||||||
bool userVerificationEnabled() const;
|
bool userVerificationEnabled() const;
|
||||||
bool isSelf() const;
|
bool isSelf() const;
|
||||||
|
bool isUsernameEditingAllowed() const;
|
||||||
|
|
||||||
Q_INVOKABLE void verify(QString device = "");
|
Q_INVOKABLE void verify(QString device = "");
|
||||||
Q_INVOKABLE void unverify(QString device = "");
|
Q_INVOKABLE void unverify(QString device = "");
|
||||||
|
@ -110,15 +115,19 @@ public:
|
||||||
Q_INVOKABLE void kickUser();
|
Q_INVOKABLE void kickUser();
|
||||||
Q_INVOKABLE void startChat();
|
Q_INVOKABLE void startChat();
|
||||||
Q_INVOKABLE void changeUsername(QString username);
|
Q_INVOKABLE void changeUsername(QString username);
|
||||||
|
Q_INVOKABLE void allowUsernameEditing(bool allow);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void userStatusChanged();
|
void userStatusChanged();
|
||||||
|
|
||||||
|
void usernameEditingChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString roomid_, userid_;
|
QString roomid_, userid_;
|
||||||
DeviceInfoModel deviceList_;
|
DeviceInfoModel deviceList_;
|
||||||
bool isUserVerified = false;
|
bool isUserVerified = false;
|
||||||
bool hasMasterKey = false;
|
bool hasMasterKey = false;
|
||||||
|
bool usernameEditing = false;
|
||||||
TimelineViewManager *manager;
|
TimelineViewManager *manager;
|
||||||
TimelineModel *model;
|
TimelineModel *model;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue