Merge pull request #687 from matrix-org/kegan/indexeddb
Use IndexedDBStore from the JS-SDKpull/21833/head
commit
cc11b3eadc
|
@ -412,6 +412,7 @@ export function stopMatrixClient() {
|
||||||
if (cli) {
|
if (cli) {
|
||||||
cli.stopClient();
|
cli.stopClient();
|
||||||
cli.removeAllListeners();
|
cli.removeAllListeners();
|
||||||
|
cli.store.deleteAllData();
|
||||||
MatrixClientPeg.unset();
|
MatrixClientPeg.unset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
import q from "q";
|
||||||
import Matrix from 'matrix-js-sdk';
|
import Matrix from 'matrix-js-sdk';
|
||||||
import utils from 'matrix-js-sdk/lib/utils';
|
import utils from 'matrix-js-sdk/lib/utils';
|
||||||
import EventTimeline from 'matrix-js-sdk/lib/models/event-timeline';
|
import EventTimeline from 'matrix-js-sdk/lib/models/event-timeline';
|
||||||
|
@ -71,7 +72,16 @@ class MatrixClientPeg {
|
||||||
const opts = utils.deepCopy(this.opts);
|
const opts = utils.deepCopy(this.opts);
|
||||||
// the react sdk doesn't work without this, so don't allow
|
// the react sdk doesn't work without this, so don't allow
|
||||||
opts.pendingEventOrdering = "detached";
|
opts.pendingEventOrdering = "detached";
|
||||||
this.get().startClient(opts);
|
|
||||||
|
let promise = this.matrixClient.store.startup();
|
||||||
|
// log any errors when starting up the database (if one exists)
|
||||||
|
promise.catch((err) => { console.error(err); });
|
||||||
|
|
||||||
|
// regardless of errors, start the client. If we did error out, we'll
|
||||||
|
// just end up doing a full initial /sync.
|
||||||
|
promise.finally(() => {
|
||||||
|
this.get().startClient(opts);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getCredentials(): MatrixClientCreds {
|
getCredentials(): MatrixClientCreds {
|
||||||
|
@ -111,6 +121,14 @@ class MatrixClientPeg {
|
||||||
if (localStorage) {
|
if (localStorage) {
|
||||||
opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
|
opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
|
||||||
}
|
}
|
||||||
|
if (window.indexedDB && localStorage) {
|
||||||
|
opts.store = new Matrix.IndexedDBStore(
|
||||||
|
new Matrix.IndexedDBStoreBackend(window.indexedDB),
|
||||||
|
new Matrix.SyncAccumulator(), {
|
||||||
|
localStorage: localStorage,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.matrixClient = Matrix.createClient(opts);
|
this.matrixClient = Matrix.createClient(opts);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue