1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

some cleanups

This commit is contained in:
Hubert Chathi
2020-03-10 15:56:33 -04:00
parent 98d955ef1f
commit 04387e78cc
2 changed files with 22 additions and 26 deletions

View File

@@ -516,21 +516,22 @@ describe("MegolmDecryption", function() {
}; };
}; };
let run = false; const sendPromise = new Promise((resolve, reject) => {
aliceClient.sendToDevice = async (msgtype, contentMap) => { aliceClient.sendToDevice = async (msgtype, contentMap) => {
run = true; expect(msgtype).toBe("org.matrix.room_key.withheld");
expect(msgtype).toBe("org.matrix.room_key.withheld"); expect(contentMap).toStrictEqual({
expect(contentMap).toStrictEqual({ '@bob:example.com': {
'@bob:example.com': { bobdevice: {
bobdevice: { algorithm: "m.megolm.v1.aes-sha2",
algorithm: "m.megolm.v1.aes-sha2", code: 'm.no_olm',
code: 'm.no_olm', reason: 'Unable to establish a secure channel.',
reason: 'Unable to establish a secure channel.', sender_key: aliceDevice.deviceCurve25519Key,
sender_key: aliceDevice.deviceCurve25519Key, },
}, },
}, });
}); resolve();
}; };
});
const event = new MatrixEvent({ const event = new MatrixEvent({
type: "m.room.message", type: "m.room.message",
@@ -540,14 +541,7 @@ describe("MegolmDecryption", function() {
content: {}, content: {},
}); });
await aliceClient._crypto.encryptEvent(event, aliceRoom); await aliceClient._crypto.encryptEvent(event, aliceRoom);
await new Promise((resolve) => { await sendPromise;
// encryptMessage retries senders in the background before giving
// up and telling them that there's no olm channel, so we need to
// wait a bit before checking that we got the message
setTimeout(resolve, 100);
});
expect(run).toBe(true);
}); });
it("throws an error describing why it doesn't have a key", async function() { it("throws an error describing why it doesn't have a key", async function() {

View File

@@ -244,8 +244,6 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
} }
} }
const errorDevices = [];
const key = this._olmDevice.getOutboundGroupSessionKey(session.sessionId); const key = this._olmDevice.getOutboundGroupSessionKey(session.sessionId);
const payload = { const payload = {
type: "m.room_key", type: "m.room_key",
@@ -269,6 +267,8 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
); );
})(), })(),
(async () => { (async () => {
const errorDevices = [];
// meanwhile, establish olm sessions for devices that we don't // meanwhile, establish olm sessions for devices that we don't
// already have a session for, and share keys with them. Use a // already have a session for, and share keys with them. Use a
// shorter timeout when fetching one-time keys. // shorter timeout when fetching one-time keys.
@@ -769,11 +769,12 @@ MegolmEncryption.prototype._notifyBlockedDevices = async function(
* @param {module:models/room} room the room the event is in * @param {module:models/room} room the room the event is in
*/ */
MegolmEncryption.prototype.prepareToEncrypt = function(room) { MegolmEncryption.prototype.prepareToEncrypt = function(room) {
logger.log(`Preparing to encrypt events for ${this._roomId}`); logger.debug(`Preparing to encrypt events for ${this._roomId}`);
if (this.encryptionPreparation) { if (this.encryptionPreparation) {
// We're already preparing something, so don't do anything else. // We're already preparing something, so don't do anything else.
// FIXME: check if we need to restart // FIXME: check if we need to restart
// (https://github.com/matrix-org/matrix-js-sdk/issues/1255)
return; return;
} }
@@ -807,7 +808,8 @@ MegolmEncryption.prototype.encryptMessage = async function(room, eventType, cont
if (this.encryptionPreparation) { if (this.encryptionPreparation) {
// If we started sending keys, wait for it to be done. // If we started sending keys, wait for it to be done.
// FIXME: check if we need to restart // FIXME: check if we need to cancel
// (https://github.com/matrix-org/matrix-js-sdk/issues/1255)
try { try {
await this.encryptionPreparation; await this.encryptionPreparation;
} catch (e) { } catch (e) {