null-guard
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
7b2e18ff7c
commit
48f219f090
1 changed files with 15 additions and 9 deletions
|
@ -45,27 +45,33 @@ 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());
|
||||||
|
if (room) {
|
||||||
room.on("RoomMember.powerLevel", this.onPermissionsChange);
|
room.on("RoomMember.powerLevel", this.onPermissionsChange);
|
||||||
room.on("RoomMember.membership", this.onPermissionsChange);
|
room.on("RoomMember.membership", this.onPermissionsChange);
|
||||||
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());
|
||||||
|
if (room) {
|
||||||
room.removeListener("RoomMember.powerLevel", this.onPermissionsChange);
|
room.removeListener("RoomMember.powerLevel", this.onPermissionsChange);
|
||||||
room.removeListener("RoomMember.membership", 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());
|
||||||
|
if (room) {
|
||||||
const me = cli.credentials.userId;
|
const me = cli.credentials.userId;
|
||||||
const canReact = room.getMyMembership() === "join" && room.currentState.maySendEvent("m.reaction", me);
|
const canReact = room.getMyMembership() === "join" && room.currentState.maySendEvent("m.reaction", me);
|
||||||
const canReply = room.maySendMessage();
|
const canReply = room.maySendMessage();
|
||||||
|
|
||||||
this.setState({canReact, canReply});
|
this.setState({canReact, canReply});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onDecrypted = () => {
|
onDecrypted = () => {
|
||||||
// When an event decrypts, it is likely to change the set of available
|
// When an event decrypts, it is likely to change the set of available
|
||||||
|
|
Loading…
Reference in a new issue