From 0633d7d3f633cdfb7e00d79a7f94e485e9a746ad Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 16 Sep 2016 03:18:47 +0100 Subject: [PATCH] track raw displayname on user objects --- lib/models/room-member.js | 15 --------------- lib/models/user.js | 12 ++++++++++++ lib/store/memory.js | 3 +++ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/models/room-member.js b/lib/models/room-member.js index c9c5bac43..f04bce6fa 100644 --- a/lib/models/room-member.js +++ b/lib/models/room-member.js @@ -212,21 +212,6 @@ function calculateDisplayName(member, event, roomState) { var displayName = event.getDirectionalContent().displayname; var selfUserId = member.userId; - /* - // FIXME: this would be great but still needs to use the - // full userId to disambiguate if needed... - - if (!displayName) { - var matches = selfUserId.match(/^@(.*?):/); - if (matches) { - return matches[1]; - } - else { - return selfUserId; - } - } - */ - if (!displayName) { return selfUserId; } diff --git a/lib/models/user.js b/lib/models/user.js index 9a33e6e21..1c4f1b70e 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -47,6 +47,7 @@ function User(userId) { this.presence = "offline"; this.presenceStatusMsg = null; this.displayName = userId; + this.rawDisplayName = userId; this.avatarUrl = null; this.lastActiveAgo = 0; this.lastPresenceTs = 0; @@ -131,6 +132,17 @@ User.prototype.setDisplayName = function(name) { } }; + +/** + * Manually set this user's non-disambiguated display name. No event is emitted + * in response to this as there is no underlying MatrixEvent to emit with. + * @param {string} name The new display name. + */ +User.prototype.setRawDisplayName = function(name) { + this.rawDisplayName = name; +}; + + /** * Manually set this user's avatar URL. No event is emitted in response to this * as there is no underlying MatrixEvent to emit with. diff --git a/lib/store/memory.js b/lib/store/memory.js index 26a397817..f183e2e05 100644 --- a/lib/store/memory.js +++ b/lib/store/memory.js @@ -101,6 +101,9 @@ module.exports.MatrixInMemoryStore.prototype = { var user = this.users[member.userId] || new User(member.userId); if (member.name) { user.setDisplayName(member.name); + if (member.events.member) { + user.setRawDisplayName(member.events.member.getDirectionalContent().displayname); + } } if (member.events.member && member.events.member.getContent().avatar_url) { user.setAvatarUrl(member.events.member.getContent().avatar_url);