From 48f219f0908d9a4e91039078cdc0c5d3783940d3 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 29 Jul 2019 12:28:30 +0100 Subject: [PATCH] null-guard Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/messages/MessageActionBar.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/components/views/messages/MessageActionBar.js b/src/components/views/messages/MessageActionBar.js index 231b7a03c3..6e47846d20 100644 --- a/src/components/views/messages/MessageActionBar.js +++ b/src/components/views/messages/MessageActionBar.js @@ -45,26 +45,32 @@ export default class MessageActionBar extends React.PureComponent { componentDidMount() { this.props.mxEvent.on("Event.decrypted", this.onDecrypted); const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); - room.on("RoomMember.powerLevel", this.onPermissionsChange); - room.on("RoomMember.membership", this.onPermissionsChange); - this.onPermissionsChange(); + if (room) { + room.on("RoomMember.powerLevel", this.onPermissionsChange); + room.on("RoomMember.membership", this.onPermissionsChange); + this.onPermissionsChange(); + } } componentWillUnmount() { this.props.mxEvent.removeListener("Event.decrypted", this.onDecrypted); const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); - room.removeListener("RoomMember.powerLevel", this.onPermissionsChange); - room.removeListener("RoomMember.membership", this.onPermissionsChange); + if (room) { + room.removeListener("RoomMember.powerLevel", this.onPermissionsChange); + room.removeListener("RoomMember.membership", this.onPermissionsChange); + } } onPermissionsChange() { const cli = MatrixClientPeg.get(); const room = cli.getRoom(this.props.mxEvent.getRoomId()); - const me = cli.credentials.userId; - const canReact = room.getMyMembership() === "join" && room.currentState.maySendEvent("m.reaction", me); - const canReply = room.maySendMessage(); + if (room) { + const me = cli.credentials.userId; + const canReact = room.getMyMembership() === "join" && room.currentState.maySendEvent("m.reaction", me); + const canReply = room.maySendMessage(); - this.setState({canReact, canReply}); + this.setState({canReact, canReply}); + } } onDecrypted = () => {