Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

MemberPresenceAvatar: fix null references #1620

Merged
merged 4 commits into from
Nov 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/components/views/avatars/MemberPresenceAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import dispatcher from "../../../dispatcher";
import * as ContextualMenu from "../../structures/ContextualMenu";
import SettingsStore from "../../../settings/SettingsStore";

// This is an avatar with presence information and controls on it.
module.exports = React.createClass({
displayName: 'MemberPresenceAvatar',

Expand All @@ -44,8 +45,15 @@ module.exports = React.createClass({
},

getInitialState: function() {
const presenceState = this.props.member.user.presence;
const presenceMessage = this.props.member.user.presenceStatusMsg;
let presenceState = null;
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 {
status: presenceState,
message: presenceMessage,
Expand Down Expand Up @@ -109,6 +117,8 @@ module.exports = React.createClass({
});

e.stopPropagation();

// XXX NB the following assumes that user is non-null, which is not valid
// const presenceState = this.props.member.user.presence;
// const presenceLastActiveAgo = this.props.member.user.lastActiveAgo;
// const presenceLastTs = this.props.member.user.lastPresenceTs;
Expand All @@ -133,7 +143,8 @@ module.exports = React.createClass({
);

// LABS: Disable presence management functions for now
if (!SettingsStore.isFeatureEnabled("feature_presence_management")) {
// Also disable the presence information if there's no status information
if (!SettingsStore.isFeatureEnabled("feature_presence_management") || !this.state.status) {
statusNode = null;
onClickFn = null;
}
Expand Down