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;
}
async _prepareSyncDecryption(events, newKeys, roomEncryption, txn, log) {
let retryEntries;
let decryptPreparation;
// when new keys arrive, also see if any events can now be retried to decrypt
if (newKeys) {
async _getSyncRetryDecryptEntries(newKeys, 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
// 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
@ -177,19 +173,7 @@ export class Room extends EventEmitter {
// add to other retry entries
retryEntries = retryEntries.concat(retryTimelineEntriesCopies);
}
if (retryEntries.length) {
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};
return retryEntries;
}
async prepareSync(roomResponse, membership, newKeys, txn, log) {
@ -208,10 +192,22 @@ export class Room extends EventEmitter {
let retryEntries;
let decryptPreparation;
if (roomEncryption) {
const events = roomResponse?.timeline?.events || [];
const result = await this._prepareSyncDecryption(events, newKeys, roomEncryption, txn, log);
retryEntries = result.retryEntries;
decryptPreparation = result.decryptPreparation;
let eventsToDecrypt = roomResponse?.timeline?.events || [];
// when new keys arrive, also see if any older events can now be retried to decrypt
if (newKeys) {
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 {