From 9f7297f62b3821966b9d8ffe9f53ef11b610baa9 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 29 Nov 2021 16:06:59 +0000 Subject: [PATCH] Get sync lifecycle not erroring on sync3 responses Still buggy as hell because we're using a live indexeddb in the test jig but at least there are no errors anymore. Comment out E2EE support. --- package.json | 2 +- snowpack.config.js | 3 +-- src/matrix/Sync3.ts | 22 ++++++++++++++++++---- src/matrix/room/Room.js | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 8cda0543..1aea67f9 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "lint": "eslint --cache src/", "lint-ts": "eslint src/ -c .ts-eslintrc.js --ext .ts", "lint-ci": "eslint src/", - "test": "impunity --entry-point src/main.js src/platform/web/Platform.js --force-esm-dirs lib/ src/", + "test": "impunity --entry-point src/main.js src/platform/web/Platform.js src/matrix/Sync3.ts --force-esm-dirs lib/ src/", "start": "snowpack dev --port 3000", "build": "node --experimental-modules scripts/build.mjs", "postinstall": "node ./scripts/post-install.js" diff --git a/snowpack.config.js b/snowpack.config.js index 68f33242..763374a3 100644 --- a/snowpack.config.js +++ b/snowpack.config.js @@ -5,8 +5,7 @@ module.exports = { mount: { // More specific paths before less specific paths (if they overlap) - "src/platform/web/docroot": "/", - "src": "/src", + "src": "/", "lib": {url: "/lib", static: true }, "assets": "/assets", /* ... */ diff --git a/src/matrix/Sync3.ts b/src/matrix/Sync3.ts index c0edb41b..59a88db5 100644 --- a/src/matrix/Sync3.ts +++ b/src/matrix/Sync3.ts @@ -232,15 +232,18 @@ export class Sync3 { let rooms: any[] = []; // process the room updates: new rooms, new timeline events, updated room names, that sort of thing. // we're kinda forced to use the logger as most functions expect an ILogItem - await this.logger.run("sync", async log => { + await this.logger.run("sync3", async log => { const syncTxn = await this.openSyncTxn(); try { + // session.prepareSync // E2EE decrypts room keys // this.session.writeSync() // write account data, device lists, etc. await Promise.all(updates.map(async (roomResponse) => { // get or create a room let room = this.session.rooms.get(roomResponse.room_id); if (!room) { room = this.session.createRoom(roomResponse.room_id); + } else { + await room.load(null, syncTxn, log); } const invite = { isDirectMessage: false, @@ -252,12 +255,16 @@ export class Sync3 { }, account_data: null, summary: null, - unread_notifications: roomResponse.notification_count, + unread_notifications: { + notification_count: roomResponse.notification_count, + highlight_count: roomResponse.highlight_count, + }, } // newKeys = [] (null for now) const preparation = await room.prepareSync( roomv2Response, "join", invite, null, syncTxn, log, ); + await room.afterPrepareSync(preparation, log); const changes = await room.writeSync( roomv2Response, isFirstSync, preparation, syncTxn, log ) @@ -283,9 +290,16 @@ export class Sync3 { return r.room.afterSync(r.changes, log); })); }); + // room.afterSyncCompleted E2EE key share requests // TODO: give valid args here - this.session.applyRoomCollectionChangesAfterSync(null, roomStates, null); + this.session.applyRoomCollectionChangesAfterSync([], rooms.map((r) => { + return { + id: r.room.id, + room: r.room, + shouldAdd: true, // TODO: only if new room and membership = join + } + }), []); }); @@ -466,7 +480,7 @@ const indexInRange = (ranges: number[][], i: number) => { export function tests() { return { - "processOps": assert => { + "processSyncOps": assert => { assert.equal(1, 1); }, }; diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 0e4d488d..1cc85180 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -66,7 +66,7 @@ export class Room extends BaseRoom { } let roomEncryption = this._roomEncryption; // encryption is enabled in this sync - if (!roomEncryption && summaryChanges.encryption) { + if (!roomEncryption && summaryChanges.encryption && false) { // TODO: re-enable and ensure we call Session._setupEncryption first log.set("enableEncryption", true); roomEncryption = this._createRoomEncryption(this, summaryChanges.encryption); }