improve typing & comment

This commit is contained in:
Michael Telatynski 2021-09-08 12:53:13 +01:00
parent 6cbdb58341
commit 467fb55e8e

View file

@ -16,6 +16,7 @@ limitations under the License.
import React, { forwardRef, useContext } from 'react'; import React, { forwardRef, useContext } from 'react';
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { IRoomEncryption } from "matrix-js-sdk/src/crypto/RoomList";
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import { MatrixClientPeg } from '../../../MatrixClientPeg'; import { MatrixClientPeg } from '../../../MatrixClientPeg';
@ -35,13 +36,16 @@ const EncryptionEvent = forwardRef<HTMLDivElement, IProps>(({ mxEvent }, ref) =>
const roomId = mxEvent.getRoomId(); const roomId = mxEvent.getRoomId();
const isRoomEncrypted = MatrixClientPeg.get().isRoomEncrypted(roomId); const isRoomEncrypted = MatrixClientPeg.get().isRoomEncrypted(roomId);
// if no change happened then skip rendering this, a shallow check is enough as events are parsed JSON const prevContent = mxEvent.getPrevContent() as IRoomEncryption;
if (!objectHasDiff(mxEvent.getPrevContent(), mxEvent.getContent())) return null; // nop const content = mxEvent.getContent<IRoomEncryption>();
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; let subtitle: string;
const dmPartner = DMRoomMap.shared().getUserIdForRoomId(roomId); const dmPartner = DMRoomMap.shared().getUserIdForRoomId(roomId);
if (mxEvent.getPrevContent().algorithm === ALGORITHM) { if (prevContent.algorithm === ALGORITHM) {
subtitle = _t("Some encryption parameters have been changed."); subtitle = _t("Some encryption parameters have been changed.");
} else if (dmPartner) { } else if (dmPartner) {
const displayName = cli?.getRoom(roomId)?.getMember(dmPartner)?.rawDisplayName || dmPartner; const displayName = cli?.getRoom(roomId)?.getMember(dmPartner)?.rawDisplayName || dmPartner;