You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Add flag to prevent emitting event.decrypted
This commit is contained in:
@@ -1692,7 +1692,7 @@ MegolmDecryption.prototype._retryDecryption = async function(senderKey, sessionI
|
|||||||
|
|
||||||
await Promise.all([...pending].map(async (ev) => {
|
await Promise.all([...pending].map(async (ev) => {
|
||||||
try {
|
try {
|
||||||
await ev.attemptDecryption(this._crypto, true);
|
await ev.attemptDecryption(this._crypto, { isRetry: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// don't die if something goes wrong
|
// don't die if something goes wrong
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -413,12 +413,13 @@ utils.extend(MatrixEvent.prototype, {
|
|||||||
* @internal
|
* @internal
|
||||||
*
|
*
|
||||||
* @param {module:crypto} crypto crypto module
|
* @param {module:crypto} crypto crypto module
|
||||||
* @param {bool} isRetry True if this is a retry (enables more logging)
|
* @param {bool} options.isRetry True if this is a retry (enables more logging)
|
||||||
|
* @param {bool} options.emit Emits "event.decrypted" if set to true
|
||||||
*
|
*
|
||||||
* @returns {Promise} promise which resolves (to undefined) when the decryption
|
* @returns {Promise} promise which resolves (to undefined) when the decryption
|
||||||
* attempt is completed.
|
* attempt is completed.
|
||||||
*/
|
*/
|
||||||
attemptDecryption: async function(crypto, isRetry) {
|
attemptDecryption: async function(crypto, options = {}) {
|
||||||
// start with a couple of sanity checks.
|
// start with a couple of sanity checks.
|
||||||
if (!this.isEncrypted()) {
|
if (!this.isEncrypted()) {
|
||||||
throw new Error("Attempt to decrypt event which isn't encrypted");
|
throw new Error("Attempt to decrypt event which isn't encrypted");
|
||||||
@@ -448,7 +449,7 @@ utils.extend(MatrixEvent.prototype, {
|
|||||||
return this._decryptionPromise;
|
return this._decryptionPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._decryptionPromise = this._decryptionLoop(crypto, isRetry);
|
this._decryptionPromise = this._decryptionLoop(crypto, options);
|
||||||
return this._decryptionPromise;
|
return this._decryptionPromise;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -493,7 +494,7 @@ utils.extend(MatrixEvent.prototype, {
|
|||||||
return recipients;
|
return recipients;
|
||||||
},
|
},
|
||||||
|
|
||||||
_decryptionLoop: async function(crypto, isRetry) {
|
_decryptionLoop: async function(crypto, options = {}) {
|
||||||
// make sure that this method never runs completely synchronously.
|
// make sure that this method never runs completely synchronously.
|
||||||
// (doing so would mean that we would clear _decryptionPromise *before*
|
// (doing so would mean that we would clear _decryptionPromise *before*
|
||||||
// it is set in attemptDecryption - and hence end up with a stuck
|
// it is set in attemptDecryption - and hence end up with a stuck
|
||||||
@@ -510,7 +511,7 @@ utils.extend(MatrixEvent.prototype, {
|
|||||||
res = this._badEncryptedMessage("Encryption not enabled");
|
res = this._badEncryptedMessage("Encryption not enabled");
|
||||||
} else {
|
} else {
|
||||||
res = await crypto.decryptEvent(this);
|
res = await crypto.decryptEvent(this);
|
||||||
if (isRetry) {
|
if (options.isRetry === true) {
|
||||||
logger.info(`Decrypted event on retry (id=${this.getId()})`);
|
logger.info(`Decrypted event on retry (id=${this.getId()})`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -518,7 +519,7 @@ utils.extend(MatrixEvent.prototype, {
|
|||||||
if (e.name !== "DecryptionError") {
|
if (e.name !== "DecryptionError") {
|
||||||
// not a decryption error: log the whole exception as an error
|
// not a decryption error: log the whole exception as an error
|
||||||
// (and don't bother with a retry)
|
// (and don't bother with a retry)
|
||||||
const re = isRetry ? 're' : '';
|
const re = options.isRetry ? 're' : '';
|
||||||
logger.error(
|
logger.error(
|
||||||
`Error ${re}decrypting event ` +
|
`Error ${re}decrypting event ` +
|
||||||
`(id=${this.getId()}): ${e.stack || e}`,
|
`(id=${this.getId()}): ${e.stack || e}`,
|
||||||
@@ -584,7 +585,9 @@ utils.extend(MatrixEvent.prototype, {
|
|||||||
// pick up the wrong contents.
|
// pick up the wrong contents.
|
||||||
this.setPushActions(null);
|
this.setPushActions(null);
|
||||||
|
|
||||||
|
if (options.emit !== false) {
|
||||||
this.emit("Event.decrypted", this, err);
|
this.emit("Event.decrypted", this, err);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ Room.prototype.decryptCriticalEvents = function() {
|
|||||||
.slice(readReceiptTimelineIndex)
|
.slice(readReceiptTimelineIndex)
|
||||||
.filter(event => event.shouldAttemptDecryption())
|
.filter(event => event.shouldAttemptDecryption())
|
||||||
.reverse()
|
.reverse()
|
||||||
.map(event => event.attemptDecryption(this._client._crypto, true));
|
.map(event => event.attemptDecryption(this._client._crypto, { isRetry: true }));
|
||||||
|
|
||||||
return Promise.allSettled(decryptionPromises);
|
return Promise.allSettled(decryptionPromises);
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ Room.prototype.decryptAllEvents = function() {
|
|||||||
.getEvents()
|
.getEvents()
|
||||||
.filter(event => event.shouldAttemptDecryption())
|
.filter(event => event.shouldAttemptDecryption())
|
||||||
.reverse()
|
.reverse()
|
||||||
.map(event => event.attemptDecryption(this._client._crypto, true));
|
.map(event => event.attemptDecryption(this._client._crypto, { isRetry: true }));
|
||||||
|
|
||||||
return Promise.allSettled(decryptionPromises);
|
return Promise.allSettled(decryptionPromises);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user