Page MenuHomePhorge

D155.1732325521.diff
No OneTemporary

Size
7 KB
Referenced Files
None
Subscribers
None

D155.1732325521.diff

diff --git a/src/contents/ui/UserPage.qml b/src/contents/ui/UserPage.qml
--- a/src/contents/ui/UserPage.qml
+++ b/src/contents/ui/UserPage.qml
@@ -73,6 +73,19 @@
}
}
}
+ property bool updatingSelfName: false
+ property var updateSelfName: Kazv.AsyncHandler {
+ trigger: () => {
+ userPage.updatingSelfName = true;
+ return userPage.room.setSelfName(selfNameInput.text);
+ }
+ onResolved: (success, data) => {
+ userPage.updatingSelfName = false;
+ if (!success) {
+ showPassiveNotification(l10n.get('user-page-update-self-name-failed-prompt', { errorCode: data.errorCode, errorMsg: data.error }));
+ }
+ }
+ }
Component.onCompleted: {
userPage.ensureMemberEvent.call();
@@ -165,6 +178,26 @@
}
}
+ RowLayout {
+ visible: room.membership === MK.MatrixRoom.Join && userPage.userId === matrixSdk.userId
+ TextField {
+ id: selfNameInput
+ objectName: 'selfNameInput'
+ placeholderText: l10n.get('user-page-self-name-placeholder')
+ Layout.fillWidth: true
+ Accessible.name: l10n.get('user-page-self-name-prompt')
+ enabled: !userPage.updatingSelfName
+ text: userPage.user.name
+ }
+
+ Button {
+ objectName: 'saveSelfNameButton'
+ text: l10n.get('user-page-save-self-name-action')
+ enabled: !userPage.updatingSelfName
+ onClicked: userPage.updateSelfName.call()
+ }
+ }
+
RowLayout {
// Do not allow user to set a name override for themselves
visible: userPage.userId !== matrixSdk.userId
diff --git a/src/l10n/cmn-Hans/100-ui.ftl b/src/l10n/cmn-Hans/100-ui.ftl
--- a/src/l10n/cmn-Hans/100-ui.ftl
+++ b/src/l10n/cmn-Hans/100-ui.ftl
@@ -339,6 +339,10 @@
user-page-overrided-name-placeholder = 自定义显示名...
user-page-save-name-override-action = 保存
user-page-update-name-override-failed-prompt = 无法设置自定义显示名。错误码:{ $error }。错误讯息:{ $errorMsg }。
+user-page-self-name-prompt = 自己在房间里的显示名:
+user-page-self-name-placeholder = 自己在房间里的显示名...
+user-page-save-self-name-action = 保存
+user-page-update-self-name-failed-prompt = 无法设置自己在房间里的显示名。错误码:{ $error }。错误讯息:{ $errorMsg }。
room-invite-page-title = 邀请用户到 { $room }
room-invite-page-invite-failed-prompt = 无法邀请用户。错误码:{ $errorCode }。错误讯息:{ $errorMsg }。
diff --git a/src/l10n/en/100-ui.ftl b/src/l10n/en/100-ui.ftl
--- a/src/l10n/en/100-ui.ftl
+++ b/src/l10n/en/100-ui.ftl
@@ -367,6 +367,10 @@
user-page-overrided-name-placeholder = Custom display name...
user-page-save-name-override-action = Save
user-page-update-name-override-failed-prompt = Unable to set custom display name. Error code: { $errorCode }. Error message: { $errorMsg }.
+user-page-self-name-prompt = Own display name in room:
+user-page-self-name-placeholder = Own display name in room...
+user-page-save-self-name-action = Save
+user-page-update-self-name-failed-prompt = Unable to set own display name in room. Error code: { $errorCode }. Error message: { $errorMsg }.
room-invite-page-title = Inviting user to { $room }
room-invite-page-invite-failed-prompt = Unable to invite user. Error code: { $errorCode }. Error message: { $errorMsg }.
diff --git a/src/matrix-room.hpp b/src/matrix-room.hpp
--- a/src/matrix-room.hpp
+++ b/src/matrix-room.hpp
@@ -96,6 +96,8 @@
Q_INVOKABLE MatrixPromise *sendStateEvent(const QJsonObject &eventJson) const;
+ Q_INVOKABLE MatrixPromise *setSelfName(const QString &name) const;
+
Q_INVOKABLE MatrixPromise *redactEvent(QString eventId, QString reason) const;
Q_INVOKABLE MatrixPromise *removeLocalEcho(QString txnId) const;
diff --git a/src/matrix-room.cpp b/src/matrix-room.cpp
--- a/src/matrix-room.cpp
+++ b/src/matrix-room.cpp
@@ -267,6 +267,18 @@
return new MatrixPromise(m_room.sendStateEvent(Event(json(eventJson))));
}
+MatrixPromise *MatrixRoom::setSelfName(const QString &name) const
+{
+ auto eventJson = m_room.state({"m.room.member", m_selfUserId.get()}).make().get().originalJson().get();
+ eventJson.merge_patch(json{
+ {"content", {
+ {"displayname", name.toStdString()},
+ }},
+ });
+
+ return new MatrixPromise(m_room.sendStateEvent(Event(json(eventJson))));
+}
+
nlohmann::json MatrixRoom::makeMediaFileMessageJson(QString fileName, QString mimeType, qint64 fileSize, QString mxcUri) const
{
static auto available_msgtype = std::array<std::string, 3>{"m.audio", "m.video", "m.image"};
diff --git a/src/tests/quick-tests/tst_UserPage.qml b/src/tests/quick-tests/tst_UserPage.qml
--- a/src/tests/quick-tests/tst_UserPage.qml
+++ b/src/tests/quick-tests/tst_UserPage.qml
@@ -42,11 +42,13 @@
function userPowerLevel(userId) {
return powerLevelMapping[userId];
}
+ property var membership: MK.MatrixRoom.Join
property var setUserPowerLevel: mockHelper.promise()
property var ensureStateEvent: mockHelper.promise()
property var kickUser: mockHelper.promise()
property var banUser: mockHelper.promise()
property var unbanUser: mockHelper.promise()
+ property var setSelfName: mockHelper.promise()
}
property var userPage: null
@@ -77,6 +79,7 @@
function init() {
mockHelper.clearAll();
+ room.membership = MK.MatrixRoom.Join;
userPage = userPageComp.createObject(layout);
userPageWithoutName = userPageWithoutNameComp.createObject(layout);
layout.children = [userPage, userPageWithoutName];
@@ -362,5 +365,52 @@
verify(nameLabel.text === '@mew:example.com');
verify(!idLabel.visible);
}
+
+ function test_nonSelfName() {
+ const selfNameInput = findChild(userPage, 'selfNameInput');
+ verify(!selfNameInput.visible);
+ }
+
+ function test_nonJoinedRoomSelfName() {
+ userPage.userId = '@foo:example.com';
+ userPage.user.userId = '@foo:example.com';
+ upper.room.membership = MK.MatrixRoom.Invite;
+ const selfNameInput = findChild(userPage, 'selfNameInput');
+ verify(!selfNameInput.visible);
+ }
+
+ function test_selfName() {
+ userPage.userId = '@foo:example.com';
+ userPage.user.userId = '@foo:example.com';
+ const selfNameInput = findChild(userPage, 'selfNameInput');
+ verify(selfNameInput.visible);
+ verify(selfNameInput.text === 'mew');
+ selfNameInput.text = 'some others';
+ const button = findChild(userPage, 'saveSelfNameButton');
+ verify(button.enabled);
+ mouseClick(button);
+ tryVerify(() => room.setSelfName.calledTimes() === 1);
+ verify(!button.enabled);
+ verify(!selfNameInput.enabled);
+ verify(room.setSelfName.lastArgs()[0] === 'some others');
+ room.setSelfName.lastRetVal().resolve(/* succ = */ true, {});
+ tryVerify(() => button.enabled);
+ verify(selfNameInput.enabled);
+ }
+
+ function test_updateSelfNameFailed() {
+ userPage.userId = '@foo:example.com';
+ userPage.user.userId = '@foo:example.com';
+ const selfNameInput = findChild(userPage, 'selfNameInput');
+ selfNameInput.text = 'some others';
+ const button = findChild(userPage, 'saveSelfNameButton');
+ verify(button.enabled);
+ mouseClick(button);
+ tryVerify(() => room.setSelfName.calledTimes() === 1);
+ room.setSelfName.lastRetVal().resolve(/* succ = */ false, {});
+ tryVerify(() => button.enabled);
+ verify(selfNameInput.enabled);
+ verify(showPassiveNotification.calledTimes() === 1);
+ }
}
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 5:32 PM (4 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39039
Default Alt Text
D155.1732325521.diff (7 KB)

Event Timeline