mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Merge pull request #322 from vector-im/bwindels/send-waits-for-keyshare
Sending a message waits for (ongoing) keyshare
This commit is contained in:
commit
fe6f0c9b48
@ -46,6 +46,7 @@ export class RoomEncryption {
|
|||||||
this._clock = clock;
|
this._clock = clock;
|
||||||
this._isFlushingRoomKeyShares = false;
|
this._isFlushingRoomKeyShares = false;
|
||||||
this._lastKeyPreShareTime = null;
|
this._lastKeyPreShareTime = null;
|
||||||
|
this._keySharePromise = null;
|
||||||
this._disposed = false;
|
this._disposed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,16 +266,29 @@ export class RoomEncryption {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._lastKeyPreShareTime = this._clock.createMeasure();
|
this._lastKeyPreShareTime = this._clock.createMeasure();
|
||||||
|
try {
|
||||||
|
this._keySharePromise = (async () => {
|
||||||
const roomKeyMessage = await this._megolmEncryption.ensureOutboundSession(this._room.id, this._encryptionParams);
|
const roomKeyMessage = await this._megolmEncryption.ensureOutboundSession(this._room.id, this._encryptionParams);
|
||||||
if (roomKeyMessage) {
|
if (roomKeyMessage) {
|
||||||
await log.wrap("share key", log => this._shareNewRoomKey(roomKeyMessage, hsApi, log));
|
await log.wrap("share key", log => this._shareNewRoomKey(roomKeyMessage, hsApi, log));
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
|
await this._keySharePromise;
|
||||||
|
} finally {
|
||||||
|
this._keySharePromise = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async encrypt(type, content, hsApi, log) {
|
async encrypt(type, content, hsApi, log) {
|
||||||
|
// ensureMessageKeyIsShared is still running,
|
||||||
|
// wait for it to create and share a key if needed
|
||||||
|
if (this._keySharePromise) {
|
||||||
|
log.set("waitForRunningKeyShare", true);
|
||||||
|
await this._keySharePromise;
|
||||||
|
}
|
||||||
const megolmResult = await log.wrap("megolm encrypt", () => this._megolmEncryption.encrypt(this._room.id, type, content, this._encryptionParams));
|
const megolmResult = await log.wrap("megolm encrypt", () => this._megolmEncryption.encrypt(this._room.id, type, content, this._encryptionParams));
|
||||||
if (megolmResult.roomKeyMessage) {
|
if (megolmResult.roomKeyMessage) {
|
||||||
log.wrapDetached("share key", log => this._shareNewRoomKey(megolmResult.roomKeyMessage, hsApi, log));
|
await log.wrap("share key", log => this._shareNewRoomKey(megolmResult.roomKeyMessage, hsApi, log));
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
type: ENCRYPTED_TYPE,
|
type: ENCRYPTED_TYPE,
|
||||||
|
Loading…
Reference in New Issue
Block a user