Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Call onHeightChanged from componentDidUpdate
Browse files Browse the repository at this point in the history
... to ensure that we don't call it if there was no change to the verification
status.
  • Loading branch information
richvdh committed Dec 17, 2022
1 parent 46e47a8 commit 0f79d6f
Showing 1 changed file with 13 additions and 40 deletions.
53 changes: 13 additions & 40 deletions src/components/views/rooms/EventTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,11 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
this.threadState?.off(NotificationStateEvents.Update, this.onThreadStateUpdate);
}

public componentDidUpdate(prevProps: Readonly<EventTileProps>) {
public componentDidUpdate(prevProps: Readonly<EventTileProps>, prevState: Readonly<IState>) {
// If the verification state changed, the height might have changed
if (prevState.verified !== this.state.verified) {
this.props.onHeightChanged();
}
// If we're not listening for receipts and expect to be, register a listener.
if (!this.isListeningForReceipts && (this.shouldShowSentReceipt || this.shouldShowSendingReceipt)) {
MatrixClientPeg.get().on(RoomEvent.Receipt, this.onRoomReceipt);
Expand Down Expand Up @@ -586,10 +590,9 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
*/
private onDecrypted = () => {
// we need to re-verify the sending device.
// (we call onHeightChanged in verifyEvent to handle the case where decryption
// has caused a change in size of the event tile)
this.verifyEvent();
this.forceUpdate();
// decryption might, of course, trigger a height change, so call onHeightChanged after the re-render
this.forceUpdate(this.props.onHeightChanged);
};

private onDeviceVerificationChanged = (userId: string, device: string): void => {
Expand Down Expand Up @@ -617,66 +620,36 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>

if (encryptionInfo.mismatchedSender) {
// something definitely wrong is going on here
this.setState(
{
verified: E2EState.Warning,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
this.setState({ verified: E2EState.Warning });
return;
}

if (!userTrust.isCrossSigningVerified()) {
// If the message is unauthenticated, then display a grey
// shield, otherwise if the user isn't cross-signed then
// nothing's needed
this.setState(
{
verified: encryptionInfo.authenticated ? E2EState.Normal : E2EState.Unauthenticated,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
this.setState({ verified: encryptionInfo.authenticated ? E2EState.Normal : E2EState.Unauthenticated });
return;
}

const eventSenderTrust =
encryptionInfo.sender && MatrixClientPeg.get().checkDeviceTrust(senderId, encryptionInfo.sender.deviceId);
if (!eventSenderTrust) {
this.setState(
{
verified: E2EState.Unknown,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
this.setState({ verified: E2EState.Unknown });
return;
}

if (!eventSenderTrust.isVerified()) {
this.setState(
{
verified: E2EState.Warning,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
this.setState({ verified: E2EState.Warning });
return;
}

if (!encryptionInfo.authenticated) {
this.setState(
{
verified: E2EState.Unauthenticated,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
this.setState({ verified: E2EState.Unauthenticated });
return;
}

this.setState(
{
verified: E2EState.Verified,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
this.setState({ verified: E2EState.Verified });
}

private propsEqual(objA: EventTileProps, objB: EventTileProps): boolean {
Expand Down

0 comments on commit 0f79d6f

Please sign in to comment.