make a method to determine only the retry entries rather

This commit is contained in:
Bruno Windels 2021-03-03 13:53:52 +01:00
parent 404dbcd065
commit 6771303086

View File

@ -156,13 +156,9 @@ export class Room extends EventEmitter {
return request; return request;
} }
async _prepareSyncDecryption(events, newKeys, roomEncryption, txn, log) { async _getSyncRetryDecryptEntries(newKeys, txn) {
let retryEntries;
let decryptPreparation;
// when new keys arrive, also see if any events can now be retried to decrypt
if (newKeys) {
const entriesPerKey = await Promise.all(newKeys.map(key => this._getRetryDecryptEntriesForKey(key, txn))); const entriesPerKey = await Promise.all(newKeys.map(key => this._getRetryDecryptEntriesForKey(key, txn)));
retryEntries = entriesPerKey.reduce((allEntries, entries) => allEntries.concat(entries), []); let retryEntries = entriesPerKey.reduce((allEntries, entries) => allEntries.concat(entries), []);
// If we have the timeline open, see if there are more entries for the new keys // If we have the timeline open, see if there are more entries for the new keys
// as we only store missing session information for synced events, not backfilled. // as we only store missing session information for synced events, not backfilled.
// We want to decrypt all events we can though if the user is looking // We want to decrypt all events we can though if the user is looking
@ -177,19 +173,7 @@ export class Room extends EventEmitter {
// add to other retry entries // add to other retry entries
retryEntries = retryEntries.concat(retryTimelineEntriesCopies); retryEntries = retryEntries.concat(retryTimelineEntriesCopies);
} }
if (retryEntries.length) { return retryEntries;
log.set("retry", retryEntries.length);
events = events.concat(retryEntries.map(entry => entry.event));
}
}
const eventsToDecrypt = events.filter(event => {
return event?.type === EVENT_ENCRYPTED_TYPE;
});
if (eventsToDecrypt.length) {
decryptPreparation = await roomEncryption.prepareDecryptAll(
eventsToDecrypt, newKeys, DecryptionSource.Sync, txn);
}
return {retryEntries, decryptPreparation};
} }
async prepareSync(roomResponse, membership, newKeys, txn, log) { async prepareSync(roomResponse, membership, newKeys, txn, log) {
@ -208,10 +192,22 @@ export class Room extends EventEmitter {
let retryEntries; let retryEntries;
let decryptPreparation; let decryptPreparation;
if (roomEncryption) { if (roomEncryption) {
const events = roomResponse?.timeline?.events || []; let eventsToDecrypt = roomResponse?.timeline?.events || [];
const result = await this._prepareSyncDecryption(events, newKeys, roomEncryption, txn, log); // when new keys arrive, also see if any older events can now be retried to decrypt
retryEntries = result.retryEntries; if (newKeys) {
decryptPreparation = result.decryptPreparation; retryEntries = await this._getSyncRetryDecryptEntries(newKeys, txn);
if (retryEntries.length) {
log.set("retry", retryEntries.length);
eventsToDecrypt = eventsToDecrypt.concat(retryEntries.map(entry => entry.event));
}
}
eventsToDecrypt = eventsToDecrypt.filter(event => {
return event?.type === EVENT_ENCRYPTED_TYPE;
});
if (eventsToDecrypt.length) {
decryptPreparation = await roomEncryption.prepareDecryptAll(
eventsToDecrypt, newKeys, DecryptionSource.Sync, txn);
}
} }
return { return {