diff --git a/src/crypto/index.js b/src/crypto/index.js index 9b4a5bd6eec..5c12076c554 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -57,6 +57,7 @@ import {IllegalMethod} from "./verification/IllegalMethod"; import {KeySignatureUploadError} from "../errors"; import {decryptAES, encryptAES} from './aes'; import {DehydrationManager} from './dehydration'; +import { MatrixEvent } from "../models/event"; const DeviceVerification = DeviceInfo.DeviceVerification; @@ -3028,19 +3029,26 @@ Crypto.prototype.encryptEvent = async function(event, room) { * finished decrypting. Rejects with an `algorithms.DecryptionError` if there * is a problem decrypting the event. */ -Crypto.prototype.decryptEvent = function(event) { +Crypto.prototype.decryptEvent = async function(event) { if (event.isRedacted()) { - return Promise.resolve({ + const redactionEvent = new MatrixEvent(event.getUnsigned().redacted_because); + const decryptedEvent = await this.decryptEvent(redactionEvent); + + return { clearEvent: { room_id: event.getRoomId(), type: "m.room.message", content: {}, + unsigned: { + redacted_because: decryptedEvent.clearEvent, + }, }, - }); + }; + } else { + const content = event.getWireContent(); + const alg = this._getRoomDecryptor(event.getRoomId(), content.algorithm); + return await alg.decryptEvent(event); } - const content = event.getWireContent(); - const alg = this._getRoomDecryptor(event.getRoomId(), content.algorithm); - return alg.decryptEvent(event); }; /** diff --git a/src/models/event.js b/src/models/event.js index 8a062caefa1..4124df7085b 100644 --- a/src/models/event.js +++ b/src/models/event.js @@ -811,6 +811,24 @@ utils.extend(MatrixEvent.prototype, { return this.getType() === "m.room.redaction"; }, + /** + * Get the (decrypted, if necessary) redaction event JSON + * if event was redacted + * + * @returns {object} The redaction event JSON, or an empty object + */ + getRedactionEvent: function() { + if (!this.isRedacted()) return null; + + if (this._clearEvent.unsigned) { + return this._clearEvent.unsigned.redacted_because; + } else if (this.event.unsigned.redacted_because) { + return this.event.unsigned.redacted_because; + } else { + return {}; + } + }, + /** * Get the push actions, if known, for this event *