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(); super();
this._roomVM = roomVM; this._roomVM = roomVM;
this._isEmpty = true; this._isEmpty = true;
this._ensureKeyPromise = null;
} }
get isEncrypted() { get isEncrypted() {
@ -188,8 +189,16 @@ class ComposerViewModel extends ViewModel {
return !this._isEmpty; return !this._isEmpty;
} }
setInput(text) { async setInput(text) {
const wasEmpty = this._isEmpty;
this._isEmpty = text.length === 0; this._isEmpty = text.length === 0;
this.emitChange("canSend"); 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 */ /** 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); const roomKeyMessage = await this._megolmEncryption.ensureOutboundSession(this._room.id, this._encryptionParams);
if (roomKeyMessage) { if (roomKeyMessage) {
await this._deviceTracker.trackRoom(this._room);
await this._shareNewRoomKey(roomKeyMessage, hsApi); await this._shareNewRoomKey(roomKeyMessage, hsApi);
} }
} }

View file

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