From 467fb55e8ecaecf6083e49538464d1a8b81041cc Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Sep 2021 12:53:13 +0100 Subject: [PATCH] improve typing & comment --- src/components/views/messages/EncryptionEvent.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/views/messages/EncryptionEvent.tsx b/src/components/views/messages/EncryptionEvent.tsx index 80b60f1fe7..8f352610e0 100644 --- a/src/components/views/messages/EncryptionEvent.tsx +++ b/src/components/views/messages/EncryptionEvent.tsx @@ -16,6 +16,7 @@ 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'; @@ -35,13 +36,16 @@ const EncryptionEvent = forwardRef(({ mxEvent }, ref) => const roomId = mxEvent.getRoomId(); const isRoomEncrypted = MatrixClientPeg.get().isRoomEncrypted(roomId); - // if no change happened then skip rendering this, a shallow check is enough as events are parsed JSON - if (!objectHasDiff(mxEvent.getPrevContent(), mxEvent.getContent())) return null; // nop + const prevContent = mxEvent.getPrevContent() as IRoomEncryption; + const content = mxEvent.getContent(); - if (mxEvent.getContent().algorithm === ALGORITHM && isRoomEncrypted) { + // 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 (mxEvent.getPrevContent().algorithm === ALGORITHM) { + if (prevContent.algorithm === ALGORITHM) { subtitle = _t("Some encryption parameters have been changed."); } else if (dmPartner) { const displayName = cli?.getRoom(roomId)?.getMember(dmPartner)?.rawDisplayName || dmPartner;