Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F113089
D39.1732379718.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D39.1732379718.diff
View Options
diff --git a/src/contents/ui/UserNameProvider.qml b/src/contents/ui/UserNameProvider.qml
--- a/src/contents/ui/UserNameProvider.qml
+++ b/src/contents/ui/UserNameProvider.qml
@@ -12,6 +12,7 @@
QtObject {
property var user
+ property var overridedName: getOverridedName(user)
property var name: getName(user)
function getName(u) {
@@ -26,4 +27,11 @@
l10n,
);
}
+
+ function getOverridedName(u) {
+ if (!u) {
+ return '';
+ }
+ return sdkVars.userGivenNicknameMap.map[u.userId] || '';
+ }
}
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
@@ -56,6 +56,21 @@
}
}
+ property var updatingNameOverride: false
+ property var updateNameOverride: Kazv.AsyncHandler {
+ trigger: () => {
+ userPage.updatingNameOverride = true;
+ return sdkVars.userGivenNicknameMap.setAndUpload(
+ userPage.userId, nameOverrideInput.text || null);
+ }
+ onResolved: (success, data) => {
+ userPage.updatingNameOverride = false;
+ if (!success) {
+ showPassiveNotification(l10n.get('user-page-update-name-override-failed-prompt', { errorCode: data.errorCode, errorMsg: data.error }));
+ }
+ }
+ }
+
Component.onCompleted: {
userPage.ensureMemberEvent.call();
userPage.ensurePowerLevels.call();
@@ -132,6 +147,26 @@
name: nameProvider.name
}
+ RowLayout {
+ // Do not allow user to set a name override for themselves
+ visible: userPage.userId !== matrixSdk.userId
+ TextField {
+ id: nameOverrideInput
+ objectName: 'nameOverrideInput'
+ placeholderText: l10n.get('user-page-overrided-name-placeholder')
+ Layout.fillWidth: true
+ enabled: !userPage.updatingNameOverride
+ text: nameProvider.overridedName
+ }
+
+ Button {
+ objectName: 'saveNameOverrideButton'
+ text: l10n.get('user-page-save-name-override-action')
+ enabled: !userPage.updatingNameOverride
+ onClicked: updateNameOverride.call()
+ }
+ }
+
RowLayout {
visible: !userPage.editingPowerLevel
Label {
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
@@ -275,6 +275,9 @@
user-page-ban-user-failed-prompt = 无法封禁用户。错误码:{ $error }。错误讯息:{ $errorMsg }。
user-page-unban-user-action = 解禁
user-page-unban-user-failed-prompt = 无法解禁用户。错误码:{ $error }。错误讯息:{ $errorMsg }。
+user-page-overrided-name-placeholder = 自定义显示名...
+user-page-save-name-override-action = 保存
+user-page-update-name-override-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
@@ -296,6 +296,9 @@
user-page-ban-user-failed-prompt = Unable to ban user. Error code: { $errorCode }. Error message: { $errorMsg }.
user-page-unban-user-action = Unban
user-page-unban-user-failed-prompt = Unable to unban user. Error code: { $errorCode }. Error message: { $errorMsg }.
+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 }.
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/tests/quick-tests/tst_UserNameProvider.qml b/src/tests/quick-tests/tst_UserNameProvider.qml
--- a/src/tests/quick-tests/tst_UserNameProvider.qml
+++ b/src/tests/quick-tests/tst_UserNameProvider.qml
@@ -56,10 +56,12 @@
providerFunctional.getName(userOverrided),
l10n.get(
'user-name-overrided', { overridedName: 'something', globalName: 'foo' }));
+ compare(providerFunctional.getOverridedName(userOverrided), 'something');
compare(
providerFunctional.getName(userNotOverrided),
'bar'
);
+ compare(providerFunctional.getOverridedName(userNotOverrided), '');
compare(
providerFunctional.getName(userIdOnly),
@@ -70,11 +72,13 @@
function test_reactiveAgainstUser() {
providerReactive.user = userComp.createObject(userNameProviderTest);
compare(providerReactive.name, 'bar');
+ compare(providerReactive.overridedName, '');
providerReactive.user.userId = '@foo:tusooa.xyz';
compare(
providerReactive.name,
l10n.get(
'user-name-overrided', { overridedName: 'something', globalName: 'bar' }));
+ compare(providerReactive.overridedName, 'something');
providerReactive.user = userComp.createObject(userNameProviderTest, {
userId: '@foo:tusooa.xyz',
@@ -84,11 +88,13 @@
providerReactive.name,
l10n.get(
'user-name-overrided', { overridedName: 'something', globalName: 'foo' }));
+ compare(providerReactive.overridedName, 'something');
}
function test_reactiveAgainstOverrides() {
providerReactive.user = userComp.createObject(userNameProviderTest);
compare(providerReactive.name, 'bar');
+ compare(providerReactive.overridedName, '');
sdkVars.userGivenNicknameMap.map = {
'@bar:tusooa.xyz': 'something',
};
@@ -97,5 +103,6 @@
providerReactive.name,
l10n.get(
'user-name-overrided', { overridedName: 'something', globalName: 'bar' }));
+ compare(providerReactive.overridedName, 'something');
}
}
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
@@ -18,7 +18,24 @@
height: 600
property var l10n: Helpers.fluentMock
- property var matrixSdk: TestHelpers.MatrixSdkMock {}
+ property var matrixSdk: TestHelpers.MatrixSdkMock {
+ property var userId: '@foo:example.com'
+ }
+ property var sdkVars: QtObject {
+ property var userGivenNicknameMap: QtObject {
+ id: gnMap
+ property var map: ({})
+ property var _setAndUploadCalled: 0
+ property var _setAndUploadArgs: []
+ property var _setAndUploadPromise: null
+ function setAndUpload(userId, value) {
+ ++_setAndUploadCalled;
+ _setAndUploadArgs = [userId, value];
+ _setAndUploadPromise = promiseComp.createObject(upper);
+ return _setAndUploadPromise;
+ }
+ }
+ }
property var lastNotification: undefined
@@ -88,9 +105,14 @@
Kazv.UserPage {
id: userPage
userId: '@mew:example.com'
- user: ({})
+ user: ({ userId: '@mew:example.com', name: 'mew' })
room: upper.room
}
+
+ Kazv.UserPage {
+ id: userPageSelf
+ userId: '@foo:example.com'
+ }
}
TestCase {
@@ -118,6 +140,10 @@
userPage.unbanningUser = false;
upper.lastNotification = undefined;
userPage.user = ({});
+ gnMap.map = {};
+ gnMap._setAndUploadCalled = 0;
+ gnMap._setAndUploadArgs = [];
+ gnMap._setAndUploadPromise = null;
}
function test_powerLevel() {
@@ -311,4 +337,65 @@
// is performed on the user
tryVerify(() => kickButton.enabled, 1000);
}
+
+ function test_overridedName() {
+ const input = findChild(userPage, 'nameOverrideInput');
+ compare(input.text, '');
+
+ gnMap.map = { '@mew:example.com': 'something' };
+ compare(input.text, 'something');
+
+ verify(!findChild(userPageSelf, 'nameOverrideInput').visible);
+ }
+
+ function test_updateOverridedName() {
+ const input = findChild(userPage, 'nameOverrideInput');
+ compare(input.text, '');
+ verify(input.enabled);
+ input.text = 'something';
+ const saveButton = findChild(userPage, 'saveNameOverrideButton');
+ verify(saveButton.enabled);
+ mouseClick(saveButton);
+ tryVerify(() => !input.enabled);
+ verify(!saveButton.enabled);
+ compare(gnMap._setAndUploadCalled, 1);
+ verify(TestHelpers.deepEqual(gnMap._setAndUploadArgs, ['@mew:example.com', 'something']));
+ gnMap._setAndUploadPromise.resolve(true, {});
+ tryVerify(() => input.enabled);
+ verify(saveButton.enabled);
+ }
+
+ function test_updateOverridedNameFailed() {
+ const input = findChild(userPage, 'nameOverrideInput');
+ compare(input.text, '');
+ verify(input.enabled);
+ input.text = 'something';
+ const saveButton = findChild(userPage, 'saveNameOverrideButton');
+ verify(saveButton.enabled);
+ mouseClick(saveButton);
+ tryVerify(() => !input.enabled);
+ verify(!saveButton.enabled);
+ compare(gnMap._setAndUploadCalled, 1);
+ verify(TestHelpers.deepEqual(gnMap._setAndUploadArgs, ['@mew:example.com', 'something']));
+ gnMap._setAndUploadPromise.resolve(false, {});
+ tryVerify(() => input.enabled);
+ verify(saveButton.enabled);
+ }
+
+ function test_removeOverridedName() {
+ gnMap.map = { '@mew:example.com': 'something' };
+ const input = findChild(userPage, 'nameOverrideInput');
+ compare(input.text, 'something');
+ input.text = '';
+ const saveButton = findChild(userPage, 'saveNameOverrideButton');
+ verify(saveButton.enabled);
+ mouseClick(saveButton);
+ tryVerify(() => !input.enabled);
+ verify(!saveButton.enabled);
+ compare(gnMap._setAndUploadCalled, 1);
+ verify(TestHelpers.deepEqual(gnMap._setAndUploadArgs, ['@mew:example.com', null]));
+ gnMap._setAndUploadPromise.resolve(true, {});
+ tryVerify(() => input.enabled);
+ verify(saveButton.enabled);
+ }
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 8:35 AM (12 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39323
Default Alt Text
D39.1732379718.diff (9 KB)
Attached To
Mode
D39: Support editing overrided display name for users
Attached
Detach File
Event Timeline
Log In to Comment