You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Make DeviceList test pass
Includes making saveIfDirty() return a promise in case you care about when changes got saved (which the test does).
This commit is contained in:
@@ -91,6 +91,8 @@ export default class DeviceList {
|
||||
|
||||
// Timeout for a scheduled save
|
||||
this._saveTimer = null;
|
||||
// Promise resolved when device data is saved
|
||||
this._savePromise = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,14 +143,18 @@ export default class DeviceList {
|
||||
/**
|
||||
* Save the device tracking state to storage, if any changes are
|
||||
* pending other than updating the sync token
|
||||
*
|
||||
* @return {Promise<bool>} True is the data was saved, false if
|
||||
* it was not (eg. because no changes were pending)
|
||||
*/
|
||||
async saveIfDirty() {
|
||||
if (!this._dirty) return;
|
||||
if (!this._dirty) return Promise.resolve(False);
|
||||
|
||||
if (this._saveTimer === null) {
|
||||
this._saveTimer = setTimeout(() => {
|
||||
console.log('Saving device tracking data...');
|
||||
this._saveTimer = null;
|
||||
this._cryptoStore.doTxn(
|
||||
this._savePromise = this._cryptoStore.doTxn(
|
||||
'readwrite', [IndexedDBCryptoStore.STORE_DEVICE_DATA], (txn) => {
|
||||
this._cryptoStore.storeEndToEndDeviceData({
|
||||
devices: this._devices,
|
||||
@@ -158,8 +164,11 @@ export default class DeviceList {
|
||||
},
|
||||
).then(() => {
|
||||
this._dirty = false;
|
||||
return True;
|
||||
});
|
||||
}, 500);
|
||||
} else {
|
||||
return this._savePromise;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user