Skip to content

Commit 974771b

Browse files
committed
Log when OlmMachine returns unexpected value
Also condense the validity checks on the returned value
1 parent fef0d54 commit 974771b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/e2ee/CryptoClient.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,12 @@ export class CryptoClient {
169169

170170
await this.engine.lock.acquire(SYNC_LOCK_NAME, async () => {
171171
const syncResp = JSON.parse(await this.engine.machine.receiveSyncChanges(deviceMessages, deviceLists, otkCounts, unusedFallbackKeyAlgs));
172-
if (Array.isArray(syncResp)) {
173-
const decryptedToDeviceMessages = syncResp[0];
174-
if (Array.isArray(decryptedToDeviceMessages)) {
175-
for (const msg of decryptedToDeviceMessages as IToDeviceMessage[]) {
176-
this.client.emit("to_device.decrypted", msg);
177-
}
172+
if (Array.isArray(syncResp) && syncResp.length === 2 && Array.isArray(syncResp[0])) {
173+
for (const msg of syncResp[0] as IToDeviceMessage[]) {
174+
this.client.emit("to_device.decrypted", msg);
178175
}
176+
} else {
177+
LogService.error("CryptoClient", "OlmMachine.receiveSyncChanges did not return an expected value of [to-device events, room key changes]");
179178
}
180179

181180
await this.engine.run();

0 commit comments

Comments
 (0)