null-guard

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2019-07-29 12:28:30 +01:00
parent 7b2e18ff7c
commit 48f219f090

View file

@ -45,26 +45,32 @@ export default class MessageActionBar extends React.PureComponent {
componentDidMount() { componentDidMount() {
this.props.mxEvent.on("Event.decrypted", this.onDecrypted); this.props.mxEvent.on("Event.decrypted", this.onDecrypted);
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
room.on("RoomMember.powerLevel", this.onPermissionsChange); if (room) {
room.on("RoomMember.membership", this.onPermissionsChange); room.on("RoomMember.powerLevel", this.onPermissionsChange);
this.onPermissionsChange(); room.on("RoomMember.membership", this.onPermissionsChange);
this.onPermissionsChange();
}
} }
componentWillUnmount() { componentWillUnmount() {
this.props.mxEvent.removeListener("Event.decrypted", this.onDecrypted); this.props.mxEvent.removeListener("Event.decrypted", this.onDecrypted);
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
room.removeListener("RoomMember.powerLevel", this.onPermissionsChange); if (room) {
room.removeListener("RoomMember.membership", this.onPermissionsChange); room.removeListener("RoomMember.powerLevel", this.onPermissionsChange);
room.removeListener("RoomMember.membership", this.onPermissionsChange);
}
} }
onPermissionsChange() { onPermissionsChange() {
const cli = MatrixClientPeg.get(); const cli = MatrixClientPeg.get();
const room = cli.getRoom(this.props.mxEvent.getRoomId()); const room = cli.getRoom(this.props.mxEvent.getRoomId());
const me = cli.credentials.userId; if (room) {
const canReact = room.getMyMembership() === "join" && room.currentState.maySendEvent("m.reaction", me); const me = cli.credentials.userId;
const canReply = room.maySendMessage(); const canReact = room.getMyMembership() === "join" && room.currentState.maySendEvent("m.reaction", me);
const canReply = room.maySendMessage();
this.setState({canReact, canReply}); this.setState({canReact, canReply});
}
} }
onDecrypted = () => { onDecrypted = () => {