From 7e98ea79d2051c5d8aca2f3e9613b0c471c36e44 Mon Sep 17 00:00:00 2001 From: Zoe Date: Thu, 30 Jan 2020 15:31:20 +0000 Subject: [PATCH 1/4] Fix verification toast timeouts to not stick at 0 Fixes: https://github.com/vector-im/riot-web/issues/12038 --- .../views/toasts/VerificationRequestToast.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/views/toasts/VerificationRequestToast.js b/src/components/views/toasts/VerificationRequestToast.js index d7b2880b92..fce239f655 100644 --- a/src/components/views/toasts/VerificationRequestToast.js +++ b/src/components/views/toasts/VerificationRequestToast.js @@ -33,11 +33,13 @@ export default class VerificationRequestToast extends React.PureComponent { componentDidMount() { const {request} = this.props; - this._intervalHandle = setInterval(() => { - let {counter} = this.state; - counter = Math.max(0, counter - 1); - this.setState({counter}); - }, 1000); + if (request.timeout && request.timeout > 0) { + this._intervalHandle = setInterval(() => { + let {counter} = this.state; + counter = Math.max(0, counter - 1); + this.setState({counter}); + }, 1000); + } request.on("change", this._checkRequestIsPending); // We should probably have a separate class managing the active verification toasts, // rather than monitoring this in the toast component itself, since we'll get problems @@ -120,10 +122,11 @@ export default class VerificationRequestToast extends React.PureComponent { nameLabel = _t("%(name)s (%(userId)s)", {name: user.displayName, userId}); } } + const declineLabel = this.state.counter == 0 ? _t("Decline") : _t("Decline (%(counter)s)", {counter: this.state.counter}); return (
{nameLabel}
- +
); From 49d2ed890683e1a3782a0212b85501041dce96ba Mon Sep 17 00:00:00 2001 From: Zoe Date: Thu, 30 Jan 2020 15:37:44 +0000 Subject: [PATCH 2/4] ... and take action when the counter reaches zero in verification toast --- src/components/views/toasts/VerificationRequestToast.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/views/toasts/VerificationRequestToast.js b/src/components/views/toasts/VerificationRequestToast.js index fce239f655..4f2c85acf6 100644 --- a/src/components/views/toasts/VerificationRequestToast.js +++ b/src/components/views/toasts/VerificationRequestToast.js @@ -38,6 +38,11 @@ export default class VerificationRequestToast extends React.PureComponent { let {counter} = this.state; counter = Math.max(0, counter - 1); this.setState({counter}); + + if (counter == 0) { + clearInterval(this._intervalHandle); + this.cancel(); + } }, 1000); } request.on("change", this._checkRequestIsPending); From 99b04a6f703cf547d0c40b6369f11cafd9d17c3c Mon Sep 17 00:00:00 2001 From: Zoe Date: Thu, 30 Jan 2020 15:41:26 +0000 Subject: [PATCH 3/4] lint --- src/components/views/toasts/VerificationRequestToast.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/views/toasts/VerificationRequestToast.js b/src/components/views/toasts/VerificationRequestToast.js index 4f2c85acf6..61d26c60cc 100644 --- a/src/components/views/toasts/VerificationRequestToast.js +++ b/src/components/views/toasts/VerificationRequestToast.js @@ -127,7 +127,9 @@ export default class VerificationRequestToast extends React.PureComponent { nameLabel = _t("%(name)s (%(userId)s)", {name: user.displayName, userId}); } } - const declineLabel = this.state.counter == 0 ? _t("Decline") : _t("Decline (%(counter)s)", {counter: this.state.counter}); + const declineLabel = this.state.counter == 0 ? + _t("Decline") : + _t("Decline (%(counter)s)", {counter: this.state.counter}); return (
{nameLabel}
From 36d7b8e3ed2941cb62cdd68610d1c62b4ad1958e Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 31 Jan 2020 09:59:24 +0000 Subject: [PATCH 4/4] don't close in UI, a js-sdk event will do that --- src/components/views/toasts/VerificationRequestToast.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/components/views/toasts/VerificationRequestToast.js b/src/components/views/toasts/VerificationRequestToast.js index 61d26c60cc..5125e20261 100644 --- a/src/components/views/toasts/VerificationRequestToast.js +++ b/src/components/views/toasts/VerificationRequestToast.js @@ -38,11 +38,6 @@ export default class VerificationRequestToast extends React.PureComponent { let {counter} = this.state; counter = Math.max(0, counter - 1); this.setState({counter}); - - if (counter == 0) { - clearInterval(this._intervalHandle); - this.cancel(); - } }, 1000); } request.on("change", this._checkRequestIsPending);