From 511e91a6999a0352e37f3b499f98c87696044e0f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 6 Feb 2019 22:06:47 +0000 Subject: [PATCH] small changes --- src/room/persister.js | 16 ++++++++++------ src/sync.js | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/room/persister.js b/src/room/persister.js index fe4f7563..aed18474 100644 --- a/src/room/persister.js +++ b/src/room/persister.js @@ -19,12 +19,6 @@ class RoomPersister { } async persistSync(roomResponse, txn) { - // persist state - const state = roomResponse.state; - if (state.events) { - const promises = state.events.map((event) => txn.state.setStateEventAt(this._lastSortKey, event)); - await Promise.all(promises); - } let nextKey; const timeline = roomResponse.timeline; @@ -34,6 +28,7 @@ class RoomPersister { txn.timeline.appendGap(this._roomId, nextKey, {prev_batch: timeline.prev_batch}); } nextKey = this._lastSortKey.nextKey(); + const startOfChunkSortKey = nextKey; if (timeline.events) { for(const event of timeline.events) { @@ -43,5 +38,14 @@ class RoomPersister { } // what happens here when the txn fails? this._lastSortKey = nextKey; + + // persist state + const state = roomResponse.state; + if (state.events) { + const promises = state.events.map((event) => { + txn.state.setStateEventAt(startOfChunkSortKey, event) + }); + await Promise.all(promises); + } } } \ No newline at end of file diff --git a/src/sync.js b/src/sync.js index b6c707d6..2cbfcfa5 100644 --- a/src/sync.js +++ b/src/sync.js @@ -75,7 +75,7 @@ export class Sync { parseRooms(response.rooms, async (roomId, roomResponse, membership) => { let room = session.getRoom(roomId); if (!room) { - room = session.createRoom(roomId, txn); + room = session.createRoom(roomId); } room.applySync(roomResponse, membership, txn); });