Skip to content

Commit

Permalink
indirect decryption attempts via Client (#3023)
Browse files Browse the repository at this point in the history
... to reduce the number of things referring to `client.crypto`
  • Loading branch information
richvdh authored Jan 5, 2023
1 parent 9ca3e72 commit 22f10f7
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
});
events.forEach(async (serializedEvent: Partial<IEvent>) => {
const event = mapper(serializedEvent);
if (event.getType() === EventType.RoomMessageEncrypted && this.client.isCryptoEnabled()) {
await event.attemptDecryption(this.client.crypto!);
}
await client.decryptEventIfNeeded(event);
event.setStatus(EventStatus.NOT_SENT);
this.addPendingEvent(event, event.getTxnId()!);
});
Expand Down Expand Up @@ -503,9 +501,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {

const decryptionPromises = events
.slice(readReceiptTimelineIndex)
.filter((event) => event.shouldAttemptDecryption())
.reverse()
.map((event) => event.attemptDecryption(this.client.crypto!, { isRetry: true }));
.map((event) => this.client.decryptEventIfNeeded(event, { isRetry: true }));

await Promise.allSettled(decryptionPromises);
}
Expand All @@ -521,9 +518,9 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
const decryptionPromises = this.getUnfilteredTimelineSet()
.getLiveTimeline()
.getEvents()
.filter((event) => event.shouldAttemptDecryption())
.slice(0) // copy before reversing
.reverse()
.map((event) => event.attemptDecryption(this.client.crypto!, { isRetry: true }));
.map((event) => this.client.decryptEventIfNeeded(event, { isRetry: true }));

await Promise.allSettled(decryptionPromises);
}
Expand Down

0 comments on commit 22f10f7

Please sign in to comment.