hook it up

This commit is contained in:
Bruno Windels 2020-11-06 23:43:02 +01:00
parent c6ff4c2517
commit 44a2febce9
3 changed files with 17 additions and 3 deletions

View File

@ -169,6 +169,7 @@ class ComposerViewModel extends ViewModel {
super();
this._roomVM = roomVM;
this._isEmpty = true;
this._ensureKeyPromise = null;
}
get isEncrypted() {
@ -188,8 +189,16 @@ class ComposerViewModel extends ViewModel {
return !this._isEmpty;
}
setInput(text) {
async setInput(text) {
const wasEmpty = this._isEmpty;
this._isEmpty = text.length === 0;
if (wasEmpty && !this._isEmpty && !this._ensureKeyPromise) {
this._ensureKeyPromise = this._roomVM._room.ensureMessageKeyIsShared().then(() => {
this._ensureKeyPromise = null;
});
}
if (wasEmpty !== this._isEmpty) {
this.emitChange("canSend");
}
}
}

View File

@ -247,9 +247,10 @@ export class RoomEncryption {
}
/** shares the encryption key for the next message if needed */
async ensureNextMessageKeyIsShared(hsApi) {
async ensureMessageKeyIsShared(hsApi) {
const roomKeyMessage = await this._megolmEncryption.ensureOutboundSession(this._room.id, this._encryptionParams);
if (roomKeyMessage) {
await this._deviceTracker.trackRoom(this._room);
await this._shareNewRoomKey(roomKeyMessage, hsApi);
}
}

View File

@ -354,6 +354,10 @@ export class Room extends EventEmitter {
return this._sendQueue.enqueueEvent(eventType, content);
}
async ensureMessageKeyIsShared() {
return this._roomEncryption?.ensureMessageKeyIsShared(this._hsApi);
}
/** @public */
async loadMemberList() {
if (this._memberList) {