1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

dont clear the store if its a brand new one

This commit is contained in:
Bruno Windels
2018-09-26 10:37:52 +01:00
parent 19be3dd852
commit 2560ba2980
8 changed files with 50 additions and 9 deletions

View File

@@ -3116,14 +3116,12 @@ MatrixClient.prototype.startClient = async function(opts) {
}
}
// need to vape the store when enabling LL and wasn't enabled before
let hadLLEnabledBefore = false;
const prevClientOptions = await this.store.getClientOptions();
if (prevClientOptions) {
hadLLEnabledBefore = !!prevClientOptions.lazyLoadMembers;
}
if (!hadLLEnabledBefore && opts.lazyLoadMembers) {
await this.store.deleteAllData();
throw new Error("vaped the store, you need to resync");
if (opts.lazyLoadMembers) {
const shouldClear = await this._shouldClearSyncDataIfLL();
if (shouldClear) {
await this.store.deleteAllData();
throw new Error("vaped the store, you need to resync");
}
}
if (opts.lazyLoadMembers && this._crypto) {
this._crypto.enableLazyLoading();
@@ -3143,6 +3141,22 @@ MatrixClient.prototype.startClient = async function(opts) {
this._syncApi.sync();
};
/** @return {bool} need to clear the store when enabling LL and wasn't enabled before? */
MatrixClient.prototype._shouldClearSyncDataIfLL = async function() {
let hadLLEnabledBefore = false;
const isStoreNewlyCreated = await this.store.isNewlyCreated();
if (!isStoreNewlyCreated) {
const prevClientOptions = await this.store.getClientOptions();
if (prevClientOptions) {
hadLLEnabledBefore = !!prevClientOptions.lazyLoadMembers;
}
if (!hadLLEnabledBefore) {
return true;
}
}
return false;
};
/**
* High level helper method to stop the client from polling and allow a
* clean shutdown.