1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Disambiguate display name if it contains a mxid

Fixes https://github.com/vector-im/riot-web/issues/1811

Signed-off-by: Stefan Parviainen <pafcu@iki.fi>
This commit is contained in:
Stefan Parviainen
2017-12-14 21:49:07 +01:00
parent da90a3ca78
commit 1863f1311b

View File

@@ -229,11 +229,21 @@ function calculateDisplayName(member, event, roomState) {
return displayName;
}
const userIds = roomState.getUserIdsWithDisplayName(displayName);
const otherUsers = userIds.filter(function(u) {
return u !== selfUserId;
});
if (otherUsers.length > 0) {
// Check if the name contains something that look like a mxid
// If it does, it may be someone trying to impersonate someone else
// Show full mxid in this case
// Also show mxid if there are other people with the same displayname
let disambiguate = /@.+:.+/.test(displayName);
if (!disambiguate) {
const userIds = roomState.getUserIdsWithDisplayName(displayName);
const otherUsers = userIds.filter(function(u) {
return u !== selfUserId;
});
disambiguate = otherUsers.length > 0;
}
if (disambiguate) {
return displayName + " (" + selfUserId + ")";
}
return displayName;