diff --git a/src/matrix/storage/idb/QueryTarget.js b/src/matrix/storage/idb/QueryTarget.js index 6d11932f..c0c8ed2c 100644 --- a/src/matrix/storage/idb/QueryTarget.js +++ b/src/matrix/storage/idb/QueryTarget.js @@ -42,7 +42,15 @@ export class QueryTarget { } getKey(key) { - return reqAsPromise(this._target.getKey(key)); + if (this._target.supports("getKey")) { + return reqAsPromise(this._target.getKey(key)); + } else { + return reqAsPromise(this._target.get(key)).then(value => { + if (value) { + return value[this._target.keyPath]; + } + }); + } } reduce(range, reducer, initialValue) { diff --git a/src/matrix/storage/idb/Store.js b/src/matrix/storage/idb/Store.js index 8cb8fd4c..a0ca0b96 100644 --- a/src/matrix/storage/idb/Store.js +++ b/src/matrix/storage/idb/Store.js @@ -23,6 +23,14 @@ class QueryTargetWrapper { this._qt = qt; } + get keyPath() { + if (this._qt.objectStore) { + return this._qt.objectStore.keyPath; + } else { + return this._qt.keyPath; + } + } + supports(methodName) { return !!this._qt[methodName]; } diff --git a/src/matrix/storage/idb/stores/PendingEventStore.js b/src/matrix/storage/idb/stores/PendingEventStore.js index 6492a272..00898311 100644 --- a/src/matrix/storage/idb/stores/PendingEventStore.js +++ b/src/matrix/storage/idb/stores/PendingEventStore.js @@ -52,13 +52,7 @@ export class PendingEventStore { async exists(roomId, queueIndex) { const keyRange = IDBKeyRange.only(encodeKey(roomId, queueIndex)); - let key; - if (this._eventStore.supports("getKey")) { - key = await this._eventStore.getKey(keyRange); - } else { - const value = await this._eventStore.get(keyRange); - key = value && value.key; - } + const key = await this._eventStore.getKey(keyRange); return !!key; }