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.
This commit is contained in:
Kegan Dougal 2021-11-29 16:06:59 +00:00
parent 72b18899f4
commit 9f7297f62b
4 changed files with 21 additions and 8 deletions

View file

@ -10,7 +10,7 @@
"lint": "eslint --cache src/", "lint": "eslint --cache src/",
"lint-ts": "eslint src/ -c .ts-eslintrc.js --ext .ts", "lint-ts": "eslint src/ -c .ts-eslintrc.js --ext .ts",
"lint-ci": "eslint src/", "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", "start": "snowpack dev --port 3000",
"build": "node --experimental-modules scripts/build.mjs", "build": "node --experimental-modules scripts/build.mjs",
"postinstall": "node ./scripts/post-install.js" "postinstall": "node ./scripts/post-install.js"

View file

@ -5,8 +5,7 @@
module.exports = { module.exports = {
mount: { mount: {
// More specific paths before less specific paths (if they overlap) // More specific paths before less specific paths (if they overlap)
"src/platform/web/docroot": "/", "src": "/",
"src": "/src",
"lib": {url: "/lib", static: true }, "lib": {url: "/lib", static: true },
"assets": "/assets", "assets": "/assets",
/* ... */ /* ... */

View file

@ -232,15 +232,18 @@ export class Sync3 {
let rooms: any[] = []; let rooms: any[] = [];
// process the room updates: new rooms, new timeline events, updated room names, that sort of thing. // 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 // 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(); const syncTxn = await this.openSyncTxn();
try { try {
// session.prepareSync // E2EE decrypts room keys
// this.session.writeSync() // write account data, device lists, etc. // this.session.writeSync() // write account data, device lists, etc.
await Promise.all(updates.map(async (roomResponse) => { await Promise.all(updates.map(async (roomResponse) => {
// get or create a room // get or create a room
let room = this.session.rooms.get(roomResponse.room_id); let room = this.session.rooms.get(roomResponse.room_id);
if (!room) { if (!room) {
room = this.session.createRoom(roomResponse.room_id); room = this.session.createRoom(roomResponse.room_id);
} else {
await room.load(null, syncTxn, log);
} }
const invite = { const invite = {
isDirectMessage: false, isDirectMessage: false,
@ -252,12 +255,16 @@ export class Sync3 {
}, },
account_data: null, account_data: null,
summary: null, summary: null,
unread_notifications: roomResponse.notification_count, unread_notifications: {
notification_count: roomResponse.notification_count,
highlight_count: roomResponse.highlight_count,
},
} }
// newKeys = [] (null for now) // newKeys = [] (null for now)
const preparation = await room.prepareSync( const preparation = await room.prepareSync(
roomv2Response, "join", invite, null, syncTxn, log, roomv2Response, "join", invite, null, syncTxn, log,
); );
await room.afterPrepareSync(preparation, log);
const changes = await room.writeSync( const changes = await room.writeSync(
roomv2Response, isFirstSync, preparation, syncTxn, log roomv2Response, isFirstSync, preparation, syncTxn, log
) )
@ -283,9 +290,16 @@ export class Sync3 {
return r.room.afterSync(r.changes, log); return r.room.afterSync(r.changes, log);
})); }));
}); });
// room.afterSyncCompleted E2EE key share requests
// TODO: give valid args here // 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() { export function tests() {
return { return {
"processOps": assert => { "processSyncOps": assert => {
assert.equal(1, 1); assert.equal(1, 1);
}, },
}; };

View file

@ -66,7 +66,7 @@ export class Room extends BaseRoom {
} }
let roomEncryption = this._roomEncryption; let roomEncryption = this._roomEncryption;
// encryption is enabled in this sync // 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); log.set("enableEncryption", true);
roomEncryption = this._createRoomEncryption(this, summaryChanges.encryption); roomEncryption = this._createRoomEncryption(this, summaryChanges.encryption);
} }