From 5fa5489bbddb1121fee3638377963efccfddf5b7 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sat, 17 Sep 2016 20:12:56 +0100 Subject: [PATCH] disambiguate devices by ID in memberinfo --- src/components/views/rooms/MemberDeviceInfo.js | 7 ++++--- src/components/views/rooms/MemberInfo.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/components/views/rooms/MemberDeviceInfo.js b/src/components/views/rooms/MemberDeviceInfo.js index a29fdeb81c..fe308bd1c5 100644 --- a/src/components/views/rooms/MemberDeviceInfo.js +++ b/src/components/views/rooms/MemberDeviceInfo.js @@ -145,16 +145,17 @@ export default class MemberDeviceInfo extends React.Component { ); } - var deviceName = this.props.device.getDisplayName() || this.props.device.deviceId; + var deviceName = this.props.device.ambiguous ? + (this.props.device.getDisplayName() ? this.props.device.getDisplayName() : "") + " (" + this.props.device.deviceId + ")" : + this.props.device.getDisplayName(); var info = ( -
+
{deviceName}{indicator}
); } - // add the deviceId as a titletext to help with debugging return (
{ info } diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js index 13edd384c2..ebe7196a25 100644 --- a/src/components/views/rooms/MemberInfo.js +++ b/src/components/views/rooms/MemberInfo.js @@ -115,6 +115,23 @@ module.exports = React.createClass({ } }, + _disambiguateDevices: function(devices) { + var names = Object.create(null); + for (var i = 0; i < devices.length; i++) { + var name = devices[i].getDisplayName(); + var indexList = names[name] || []; + indexList.push(i); + names[name] = indexList; + } + for (name in names) { + if (names[name].length > 1) { + names[name].forEach((j)=>{ + devices[j].ambiguous = true; + }); + } + } + }, + onDeviceVerificationChanged: function(userId, device) { if (!this._enableDevices) { return; @@ -199,6 +216,7 @@ module.exports = React.createClass({ return; } var devices = client.getStoredDevicesForUser(member.userId); + self._disambiguateDevices(devices); self.setState({devicesLoading: false, devices: devices}); }, function(err) { console.log("Error downloading devices", err);