diff --git a/src/components/views/messages/EncryptionEvent.tsx b/src/components/views/messages/EncryptionEvent.tsx index 0f716ed010..8f352610e0 100644 --- a/src/components/views/messages/EncryptionEvent.tsx +++ b/src/components/views/messages/EncryptionEvent.tsx @@ -16,26 +16,38 @@ limitations under the License. import React, { forwardRef, useContext } from 'react'; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { IRoomEncryption } from "matrix-js-sdk/src/crypto/RoomList"; import { _t } from '../../../languageHandler'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; import EventTileBubble from "./EventTileBubble"; import MatrixClientContext from "../../../contexts/MatrixClientContext"; import DMRoomMap from "../../../utils/DMRoomMap"; +import { objectHasDiff } from "../../../utils/objects"; interface IProps { mxEvent: MatrixEvent; } +const ALGORITHM = "m.megolm.v1.aes-sha2"; + const EncryptionEvent = forwardRef(({ mxEvent }, ref) => { const cli = useContext(MatrixClientContext); const roomId = mxEvent.getRoomId(); const isRoomEncrypted = MatrixClientPeg.get().isRoomEncrypted(roomId); - if (mxEvent.getContent().algorithm === 'm.megolm.v1.aes-sha2' && isRoomEncrypted) { + const prevContent = mxEvent.getPrevContent() as IRoomEncryption; + const content = mxEvent.getContent(); + + // if no change happened then skip rendering this, a shallow check is enough as all known fields are top-level. + if (!objectHasDiff(prevContent, content)) return null; // nop + + if (content.algorithm === ALGORITHM && isRoomEncrypted) { let subtitle: string; const dmPartner = DMRoomMap.shared().getUserIdForRoomId(roomId); - if (dmPartner) { + if (prevContent.algorithm === ALGORITHM) { + subtitle = _t("Some encryption parameters have been changed."); + } else if (dmPartner) { const displayName = cli?.getRoom(roomId)?.getMember(dmPartner)?.rawDisplayName || dmPartner; subtitle = _t("Messages here are end-to-end encrypted. " + "Verify %(displayName)s in their profile - tap on their avatar.", { displayName }); @@ -49,7 +61,9 @@ const EncryptionEvent = forwardRef(({ mxEvent }, ref) => title={_t("Encryption enabled")} subtitle={subtitle} />; - } else if (isRoomEncrypted) { + } + + if (isRoomEncrypted) { return