Skip to content

Commit c852f25

Browse files
committed
Tidy up
1 parent 5a0dd1e commit c852f25

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/appservice/Appservice.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ export class Appservice extends EventEmitter {
668668
return providedToken === this.registration.hs_token;
669669
}
670670

671-
private async decryptAppserivceEvent(roomId: string, encrypted: EncryptedRoomEvent): ReturnType<Appservice["processEvent"]> {
671+
private async decryptAppserviceEvent(roomId: string, encrypted: EncryptedRoomEvent): ReturnType<Appservice["processEvent"]> {
672672
const existingClient = this.cryptoClientForRoomId.get(roomId);
673673
const decryptFn = async (client: MatrixClient) => {
674674
// Also fetches state in order to decrypt room. We should throw if the client is confused.
@@ -723,12 +723,13 @@ export class Appservice extends EventEmitter {
723723
}
724724

725725
// 4. Try to enable crypto on any client to decrypt it.
726-
const userInRoom = this.intentsCache.find((_intent, userId) => userIdsInRoom.includes(userId));
726+
// We deliberately do not enable crypto on every client for performance reasons.
727+
const userInRoom = this.intentsCache.find((intent, userId) => !intent.underlyingClient.crypto?.isReady && userIdsInRoom.includes(userId));
727728
if (!userInRoom) {
728729
throw Error('No users in room, cannot decrypt');
729730
}
730-
await userInRoom.enableEncryption();
731731
try {
732+
await userInRoom.enableEncryption();
732733
return await decryptFn(userInRoom.underlyingClient);
733734
} catch (error) {
734735
LogService.debug("Appservice", `Failed to decrypt via random user ${userInRoom.userId}`, error);
@@ -882,7 +883,7 @@ export class Appservice extends EventEmitter {
882883
try {
883884
const encrypted = new EncryptedRoomEvent(event);
884885
const roomId = event['room_id'];
885-
event = await this.decryptAppserivceEvent(roomId, encrypted);
886+
event = await this.decryptAppserviceEvent(roomId, encrypted);
886887
this.emit("room.decrypted_event", roomId, event);
887888

888889
// For logging purposes: show that the event was decrypted

0 commit comments

Comments
 (0)