diff --git a/src/models/room.ts b/src/models/room.ts index 0faea02c371..ad21e626450 100644 --- a/src/models/room.ts +++ b/src/models/room.ts @@ -441,9 +441,7 @@ export class Room extends ReadReceipt { }); events.forEach(async (serializedEvent: Partial) => { 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()!); }); @@ -503,9 +501,8 @@ export class Room extends ReadReceipt { 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); } @@ -521,9 +518,9 @@ export class Room extends ReadReceipt { 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); }