Merge pull request #4119 from matrix-org/bwindels/dontleakonshowsasinverifpanel

don't leak if show_sas never comes (or already came)
This commit is contained in:
Bruno Windels 2020-02-24 16:54:15 +00:00 committed by GitHub
commit ec948eb9c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -270,6 +270,8 @@ export default class VerificationPanel extends React.PureComponent {
}; };
_onVerifierShowSas = (sasEvent) => { _onVerifierShowSas = (sasEvent) => {
const {request} = this.props;
request.verifier.off('show_sas', this._onVerifierShowSas);
this.setState({sasEvent}); this.setState({sasEvent});
}; };
@ -278,7 +280,7 @@ export default class VerificationPanel extends React.PureComponent {
const hadVerifier = this._hasVerifier; const hadVerifier = this._hasVerifier;
this._hasVerifier = !!request.verifier; this._hasVerifier = !!request.verifier;
if (!hadVerifier && this._hasVerifier) { if (!hadVerifier && this._hasVerifier) {
request.verifier.once('show_sas', this._onVerifierShowSas); request.verifier.on('show_sas', this._onVerifierShowSas);
try { try {
// on the requester side, this is also awaited in _startSAS, // on the requester side, this is also awaited in _startSAS,
// but that's ok as verify should return the same promise. // but that's ok as verify should return the same promise.
@ -299,6 +301,10 @@ export default class VerificationPanel extends React.PureComponent {
} }
componentWillUnmount() { componentWillUnmount() {
this.props.request.off("change", this._onRequestChange); const {request} = this.props;
if (request.verifier) {
request.verifier.off('show_sas', this._onVerifierShowSas);
}
request.off("change", this._onRequestChange);
} }
} }