mirror of https://github.com/vector-im/riot-web
Add glue code to make react-sdk use indexedDB
parent
c3616fd208
commit
300cd962e5
|
@ -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,17 @@ 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 = q();
|
||||||
|
if (this.matrixClient.store instanceof Matrix.IndexedDBStore) {
|
||||||
|
// load from storage before starting up.
|
||||||
|
console.log("Loading history from IndexedDB.");
|
||||||
|
promise = this.matrixClient.store.startup();
|
||||||
|
}
|
||||||
|
|
||||||
|
promise.finally(() => {
|
||||||
|
this.get().startClient(opts);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getCredentials(): MatrixClientCreds {
|
getCredentials(): MatrixClientCreds {
|
||||||
|
@ -111,6 +122,13 @@ 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), {
|
||||||
|
localStorage: localStorage,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.matrixClient = Matrix.createClient(opts);
|
this.matrixClient = Matrix.createClient(opts);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue