MemberPresenceAvatar: fix null references

avoid assuming that `member` has a `user`
This commit is contained in:
Richard van der Hoff 2017-11-17 14:35:33 +00:00
parent 02629d13d9
commit 4e7fd55fb4

View file

@ -44,8 +44,15 @@ module.exports = React.createClass({
}, },
getInitialState: function() { getInitialState: function() {
const presenceState = this.props.member.user.presence; let presenceState = null;
const presenceMessage = this.props.member.user.presenceStatusMsg; let presenceMessage = null;
// RoomMembers do not necessarily have a user.
if (this.props.member.user) {
presenceState = this.props.member.user.presence;
presenceMessage = this.props.member.user.presenceStatusMsg;
}
return { return {
status: presenceState, status: presenceState,
message: presenceMessage, message: presenceMessage,
@ -109,6 +116,8 @@ module.exports = React.createClass({
}); });
e.stopPropagation(); e.stopPropagation();
// XXX NB the following assumes that user is non-null, which is not valid
// const presenceState = this.props.member.user.presence; // const presenceState = this.props.member.user.presence;
// const presenceLastActiveAgo = this.props.member.user.lastActiveAgo; // const presenceLastActiveAgo = this.props.member.user.lastActiveAgo;
// const presenceLastTs = this.props.member.user.lastPresenceTs; // const presenceLastTs = this.props.member.user.lastPresenceTs;