Call onHeightChanged from componentDidUpdate

... to ensure that we don't call it if there was no change to the verification
status.
This commit is contained in:
Richard van der Hoff 2022-12-17 23:07:48 +00:00
parent 46e47a821e
commit c34a2bfb8c

View file

@ -470,7 +470,11 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
this.threadState?.off(NotificationStateEvents.Update, this.onThreadStateUpdate); 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) {
this.props.onHeightChanged();
}
// If we're not listening for receipts and expect to be, register a listener. // If we're not listening for receipts and expect to be, register a listener.
if (!this.isListeningForReceipts && (this.shouldShowSentReceipt || this.shouldShowSendingReceipt)) { if (!this.isListeningForReceipts && (this.shouldShowSentReceipt || this.shouldShowSendingReceipt)) {
MatrixClientPeg.get().on(RoomEvent.Receipt, this.onRoomReceipt); MatrixClientPeg.get().on(RoomEvent.Receipt, this.onRoomReceipt);
@ -586,10 +590,9 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
*/ */
private onDecrypted = () => { private onDecrypted = () => {
// we need to re-verify the sending device. // 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.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 => { private onDeviceVerificationChanged = (userId: string, device: string): void => {
@ -617,12 +620,7 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
if (encryptionInfo.mismatchedSender) { if (encryptionInfo.mismatchedSender) {
// something definitely wrong is going on here // something definitely wrong is going on here
this.setState( this.setState({ verified: E2EState.Warning });
{
verified: E2EState.Warning,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
return; return;
} }
@ -630,53 +628,28 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
// If the message is unauthenticated, then display a grey // If the message is unauthenticated, then display a grey
// shield, otherwise if the user isn't cross-signed then // shield, otherwise if the user isn't cross-signed then
// nothing's needed // nothing's needed
this.setState( this.setState({ verified: encryptionInfo.authenticated ? E2EState.Normal : E2EState.Unauthenticated });
{
verified: encryptionInfo.authenticated ? E2EState.Normal : E2EState.Unauthenticated,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
return; return;
} }
const eventSenderTrust = const eventSenderTrust =
encryptionInfo.sender && MatrixClientPeg.get().checkDeviceTrust(senderId, encryptionInfo.sender.deviceId); encryptionInfo.sender && MatrixClientPeg.get().checkDeviceTrust(senderId, encryptionInfo.sender.deviceId);
if (!eventSenderTrust) { if (!eventSenderTrust) {
this.setState( this.setState({ verified: E2EState.Unknown });
{
verified: E2EState.Unknown,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
return; return;
} }
if (!eventSenderTrust.isVerified()) { if (!eventSenderTrust.isVerified()) {
this.setState( this.setState({ verified: E2EState.Warning });
{
verified: E2EState.Warning,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
return; return;
} }
if (!encryptionInfo.authenticated) { if (!encryptionInfo.authenticated) {
this.setState( this.setState({ verified: E2EState.Unauthenticated });
{
verified: E2EState.Unauthenticated,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
return; return;
} }
this.setState( this.setState({ verified: E2EState.Verified });
{
verified: E2EState.Verified,
},
this.props.onHeightChanged,
); // Decryption may have caused a change in size
} }
private propsEqual(objA: EventTileProps, objB: EventTileProps): boolean { private propsEqual(objA: EventTileProps, objB: EventTileProps): boolean {