1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Fix DeviceList index of users by identity key

Was causing all keys to be send as unverified
This commit is contained in:
David Baker
2018-10-30 12:29:44 +00:00
parent e51d2dd36a
commit a2430dbc53

View File

@@ -142,7 +142,10 @@ export default class DeviceList {
if (!userDevices.hasOwnProperty(device)) { if (!userDevices.hasOwnProperty(device)) {
continue; continue;
} }
this._userByIdentityKey[userDevices[device].senderKey] = user; const identityKey = userDevices[device].keys['curve25519:'+device];
if (identityKey !== undefined) {
this._userByIdentityKey[identityKey] = user;
}
} }
} }
}); });
@@ -442,12 +445,22 @@ export default class DeviceList {
* @param {Object} devs New device info for user * @param {Object} devs New device info for user
*/ */
storeDevicesForUser(u, devs) { storeDevicesForUser(u, devs) {
this._devices[u] = devs; // remove previous devices from _userByIdentityKey
for (const device in devs) { if (this._devices[u] !== undefined) {
if (!devs.hasOwnProperty(device)) { for (const [deviceId, dev] of Object.entries(this._devices[u])) {
continue; const identityKey = dev.keys['curve25519:'+deviceId];
delete this._userByIdentityKey[identityKey];
} }
this._userByIdentityKey[devs[device].senderKey] = u; }
this._devices[u] = devs;
// add enw ones
for (const [deviceId, dev] of Object.entries(devs)) {
const identityKey = dev.keys['curve25519:'+deviceId];
this._userByIdentityKey[identityKey] = u;
} }
this._dirty = true; this._dirty = true;
} }
@@ -565,12 +578,22 @@ export default class DeviceList {
* @param {Object} devices deviceId->{object} the new devices * @param {Object} devices deviceId->{object} the new devices
*/ */
_setRawStoredDevicesForUser(userId, devices) { _setRawStoredDevicesForUser(userId, devices) {
this._devices[userId] = devices; // remove old devices from _userByIdentityKey
for (const device in devices) { if (this._devices[userId] !== undefined) {
if (!devices.hasOwnProperty(device)) { for (const [deviceId, dev] of Object.entries(this._devices[userId])) {
continue; const identityKey = dev.keys['curve25519:'+deviceId];
delete this._userByIdentityKey[identityKey];
} }
this._userByIdentityKey[devices[device].senderKey] = userId; }
this._devices[userId] = devices;
// add new devices into _userByIdentityKey
for (const [deviceId, dev] of Object.entries(devices)) {
const identityKey = dev.keys['curve25519:'+deviceId];
this._userByIdentityKey[identityKey] = userId;
} }
} }