From e2f8bb2ec02fedeb961670b91986f95e6e9d0368 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 25 Sep 2017 10:25:21 +0100 Subject: [PATCH] Fix NPE in MemberList _getChildCountInvited would throw an NPE if invoked before the js-sdk had found the room. Make sure we initialise the state correctly. --- src/components/views/rooms/MemberList.js | 26 ++++++++---------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/components/views/rooms/MemberList.js b/src/components/views/rooms/MemberList.js index babbfcf649..56933b5d7f 100644 --- a/src/components/views/rooms/MemberList.js +++ b/src/components/views/rooms/MemberList.js @@ -18,12 +18,7 @@ limitations under the License. import React from 'react'; import { _t } from '../../../languageHandler'; -import classNames from 'classnames'; -import Matrix from 'matrix-js-sdk'; -import Promise from 'bluebird'; var MatrixClientPeg = require("../../../MatrixClientPeg"); -var Modal = require("../../../Modal"); -var Entities = require("../../../Entities"); var sdk = require('../../../index'); var GeminiScrollbar = require('react-gemini-scrollbar'); var rate_limited_func = require('../../../ratelimitedfunc'); @@ -36,25 +31,20 @@ module.exports = React.createClass({ displayName: 'MemberList', getInitialState: function() { - const state = { - members: [], + this.memberDict = this.getMemberDict(); + const members = this.roomMembers(); + + return { + members: members, + filteredJoinedMembers: this._filterMembers(members, 'join'), + filteredInvitedMembers: this._filterMembers(members, 'invite'), + // ideally we'd size this to the page height, but // in practice I find that a little constraining truncateAtJoined: INITIAL_LOAD_NUM_MEMBERS, truncateAtInvited: INITIAL_LOAD_NUM_INVITED, searchQuery: "", }; - if (!this.props.roomId) return state; - var cli = MatrixClientPeg.get(); - var room = cli.getRoom(this.props.roomId); - if (!room) return state; - - this.memberDict = this.getMemberDict(); - - state.members = this.roomMembers(); - state.filteredJoinedMembers = this._filterMembers(state.members, 'join'); - state.filteredInvitedMembers = this._filterMembers(state.members, 'invite'); - return state; }, componentWillMount: function() {