From 9036b21b5cd4af1629e4cdc644e037b2e81df65f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 28 Sep 2021 11:34:55 +0200 Subject: [PATCH] don't interpret hex as decimal when decoding the key this fixes #515 as it was causing the gap not to be closed, because the fragment id was never equal. --- .../storage/idb/stores/TimelineEventStore.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/matrix/storage/idb/stores/TimelineEventStore.ts b/src/matrix/storage/idb/stores/TimelineEventStore.ts index d3021a88..1d261f4a 100644 --- a/src/matrix/storage/idb/stores/TimelineEventStore.ts +++ b/src/matrix/storage/idb/stores/TimelineEventStore.ts @@ -16,7 +16,7 @@ limitations under the License. import {EventKey} from "../../../room/timeline/EventKey"; import { StorageError } from "../../common"; -import { encodeUint32 } from "../utils"; +import { encodeUint32, decodeUint32 } from "../utils"; import {KeyLimits} from "../../common"; import {Store} from "../Store"; import {TimelineEvent, StateEvent} from "../../types"; @@ -46,7 +46,7 @@ function encodeKey(roomId: string, fragmentId: number, eventIndex: number): stri function decodeKey(key: string): { roomId: string, eventKey: EventKey } { const [roomId, fragmentId, eventIndex] = key.split("|"); - return {roomId, eventKey: new EventKey(parseInt(fragmentId, 10), parseInt(eventIndex, 10))}; + return {roomId, eventKey: new EventKey(decodeUint32(fragmentId), decodeUint32(eventIndex))}; } function encodeEventIdKey(roomId: string, eventId: string): string { @@ -364,7 +364,7 @@ export function tests() { "getEventKeysForIds": async assert => { const storage = await createMockStorage(); const txn = await storage.readWriteTxn([storage.storeNames.timelineEvents]); - let eventKey = EventKey.defaultLiveKey; + let eventKey = EventKey.defaultFragmentKey(109); for (const insertedId of insertedIds) { assert(await txn.timelineEvents.tryInsert(createEventEntry(eventKey.nextKey(), roomId, createEventWithId(insertedId)))); eventKey = eventKey.nextKey(); @@ -372,11 +372,11 @@ export function tests() { const eventKeyMap = await txn.timelineEvents.getEventKeysForIds(roomId, checkedIds); assert.equal(eventKeyMap.size, 2); const eventKey1 = eventKeyMap.get("$Oil2Afq2cBLqMAeJTAHjA3Is9T5Wmaa2ogVRlFJ_gzE"); - assert.equal(eventKey1.fragmentId, 0); - assert.equal(eventKey1.eventIndex, 80000001); + assert.equal(eventKey1.fragmentId, 109); + assert.equal(eventKey1.eventIndex, 0x80000001); const eventKey2 = eventKeyMap.get("$vdLgAnwjHj0cicU3MA4ynLHUBGOIFhvvksY3loqzjF"); - assert.equal(eventKey2.fragmentId, 0); - assert.equal(eventKey2.eventIndex, 80000002); + assert.equal(eventKey2.fragmentId, 109); + assert.equal(eventKey2.eventIndex, 0x80000002); } } }