From 1f6ec421f45eea48e9794e0348765fdd7806a589 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 14 Aug 2020 13:30:27 +0100 Subject: [PATCH] Make event subscriptions conditional when needed --- src/components/views/messages/MessageActionBar.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/views/messages/MessageActionBar.js b/src/components/views/messages/MessageActionBar.js index fa722a1e06..043fe1a985 100644 --- a/src/components/views/messages/MessageActionBar.js +++ b/src/components/views/messages/MessageActionBar.js @@ -114,15 +114,19 @@ export default class MessageActionBar extends React.PureComponent { static contextType = RoomContext; componentDidMount() { - this.props.mxEvent.on("Event.decrypted", this.onDecrypted); + if (this.props.mxEvent.isBeingDecrypted()) { + this.props.mxEvent.once("Event.decrypted", this.onDecrypted); + } this.props.mxEvent.on("Event.beforeRedaction", this.onBeforeRedaction); - this.props.mxEvent.on("Event.localEventIdReplaced", this.onEcho); + if (this.props.mxEvent.getId()[0] !== "!") { + this.props.mxEvent.once("Event.localEventIdReplaced", this.onEcho); + } } componentWillUnmount() { - this.props.mxEvent.removeListener("Event.decrypted", this.onDecrypted); - this.props.mxEvent.removeListener("Event.beforeRedaction", this.onBeforeRedaction); - this.props.mxEvent.removeListener("Event.localEventIdReplaced", this.onEcho); + this.props.mxEvent.off("Event.decrypted", this.onDecrypted); + this.props.mxEvent.off("Event.beforeRedaction", this.onBeforeRedaction); + this.props.mxEvent.off("Event.localEventIdReplaced", this.onEcho); } onDecrypted = () => {