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

Add new devices as we get them

This commit is contained in:
David Baker
2018-01-25 16:49:30 +01:00
parent 8c2645c5dd
commit 470bd23b3b

View File

@@ -81,7 +81,7 @@ export default class DeviceList {
this._syncToken = null; this._syncToken = null;
this._serialiser = new DeviceListUpdateSerialiser( this._serialiser = new DeviceListUpdateSerialiser(
baseApis, olmDevice, this._devices, baseApis, olmDevice, this,
); );
// userId -> promise // userId -> promise
@@ -480,6 +480,17 @@ export default class DeviceList {
return this._doKeyDownload(usersToDownload); return this._doKeyDownload(usersToDownload);
} }
/**
* Set the stored device data for a user, in raw object form
* Used only by internal class DeviceListUpdateSerialiser
*
* @param {string} userId the user to get data for
*
* @param {Object} devices deviceId->{object} the new devices
*/
_setRawStoredDevicesForUser(userId, devices) {
this._devices[userId] = devices;
}
/** /**
* Fire off download update requests for the given users, and update the * Fire off download update requests for the given users, and update the
@@ -500,13 +511,13 @@ export default class DeviceList {
const prom = this._serialiser.updateDevicesForUsers( const prom = this._serialiser.updateDevicesForUsers(
users, this._syncToken, users, this._syncToken,
).then((newDevices) => { ).then(() => {
finished(newDevices); finished(true);
}, (e) => { }, (e) => {
console.error( console.error(
'Error downloading keys for ' + users + ":", e, 'Error downloading keys for ' + users + ":", e,
); );
finished(null); finished(false);
throw e; throw e;
}); });
@@ -518,9 +529,8 @@ export default class DeviceList {
} }
}); });
const finished = (newDevices) => { const finished = (success) => {
users.forEach((u) => { users.forEach((u) => {
this._devices[u] = newDevices[u];
this._dirty = true; this._dirty = true;
// we may have queued up another download request for this user // we may have queued up another download request for this user
@@ -534,7 +544,7 @@ export default class DeviceList {
delete this._keyDownloadsInProgressByUser[u]; delete this._keyDownloadsInProgressByUser[u];
const stat = this._deviceTrackingStatus[u]; const stat = this._deviceTrackingStatus[u];
if (stat == TRACKING_STATUS_DOWNLOAD_IN_PROGRESS) { if (stat == TRACKING_STATUS_DOWNLOAD_IN_PROGRESS) {
if (newDevices) { if (success) {
// we didn't get any new invalidations since this download started: // we didn't get any new invalidations since this download started:
// this user's device list is now up to date. // this user's device list is now up to date.
this._deviceTrackingStatus[u] = TRACKING_STATUS_UP_TO_DATE; this._deviceTrackingStatus[u] = TRACKING_STATUS_UP_TO_DATE;
@@ -564,12 +574,12 @@ class DeviceListUpdateSerialiser {
/* /*
* @param {object} baseApis Base API object * @param {object} baseApis Base API object
* @param {object} olmDevice The Olm Device * @param {object} olmDevice The Olm Device
* @param {object} devices The current device list * @param {object} deviceList The device list object
*/ */
constructor(baseApis, olmDevice, devices) { constructor(baseApis, olmDevice, deviceList) {
this._baseApis = baseApis; this._baseApis = baseApis;
this._olmDevice = olmDevice; this._olmDevice = olmDevice;
this._devices = devices; // the complete device list this._deviceList = deviceList; // the device list to be updated
this._downloadInProgress = false; this._downloadInProgress = false;
@@ -582,7 +592,6 @@ class DeviceListUpdateSerialiser {
// non-null indicates that we have users queued for download. // non-null indicates that we have users queued for download.
this._queuedQueryDeferred = null; this._queuedQueryDeferred = null;
this._updatedDevices = null; // device list updates we've fetched
this._syncToken = null; // The sync token we send with the requests this._syncToken = null; // The sync token we send with the requests
} }
@@ -618,7 +627,6 @@ class DeviceListUpdateSerialiser {
return this._queuedQueryDeferred.promise; return this._queuedQueryDeferred.promise;
} }
this._updatedDevices = {};
// start a new download. // start a new download.
return this._doQueuedQueries(); return this._doQueuedQueries();
} }
@@ -665,7 +673,7 @@ class DeviceListUpdateSerialiser {
console.log('Completed key download for ' + downloadUsers); console.log('Completed key download for ' + downloadUsers);
this._downloadInProgress = false; this._downloadInProgress = false;
deferred.resolve(this._updatedDevices); deferred.resolve();
// if we have queued users, fire off another request. // if we have queued users, fire off another request.
if (this._queuedQueryDeferred) { if (this._queuedQueryDeferred) {
@@ -685,7 +693,7 @@ class DeviceListUpdateSerialiser {
// map from deviceid -> deviceinfo for this user // map from deviceid -> deviceinfo for this user
const userStore = {}; const userStore = {};
const devs = this._devices[userId]; const devs = this._deviceList.getRawStoredDevicesForUser(userId);
if (devs) { if (devs) {
Object.keys(devs).forEach((deviceId) => { Object.keys(devs).forEach((deviceId) => {
const d = DeviceInfo.fromStorage(devs[deviceId], deviceId); const d = DeviceInfo.fromStorage(devs[deviceId], deviceId);
@@ -703,7 +711,7 @@ class DeviceListUpdateSerialiser {
storage[deviceId] = userStore[deviceId].toStorage(); storage[deviceId] = userStore[deviceId].toStorage();
}); });
this._updatedDevices[userId] = storage; this._deviceList._setRawStoredDevicesForUser(userId, storage);
} }
} }