diff --git a/src/components/views/rooms/MemberList.js b/src/components/views/rooms/MemberList.js index fbc0e477a1..55fe650b7b 100644 --- a/src/components/views/rooms/MemberList.js +++ b/src/components/views/rooms/MemberList.js @@ -133,6 +133,12 @@ export default class MemberList extends React.Component { } } + get canInvite() { + const cli = MatrixClientPeg.get(); + const room = cli.getRoom(this.props.roomId); + return room && room.canInvite(cli.getUserId()); + } + _getMembersState(members) { // set the state after determining _showPresence to make sure it's // taken into account while rerendering @@ -141,6 +147,7 @@ export default class MemberList extends React.Component { members: members, filteredJoinedMembers: this._filterMembers(members, 'join'), filteredInvitedMembers: this._filterMembers(members, 'invite'), + canInvite: this.canInvite, // ideally we'd size this to the page height, but // in practice I find that a little constraining @@ -196,6 +203,8 @@ export default class MemberList extends React.Component { event.getType() === "m.room.third_party_invite") { this._updateList(); } + + if (this.canInvite !== this.state.canInvite) this.setState({ canInvite: this.canInvite }); }; _updateList = rate_limited_func(() => { @@ -455,8 +464,6 @@ export default class MemberList extends React.Component { let inviteButton; if (room && room.getMyMembership() === 'join') { - const canInvite = room.canInvite(cli.getUserId()); - let inviteButtonText = _t("Invite to this room"); const chat = CommunityPrototypeStore.instance.getSelectedCommunityGeneralChat(); if (chat && chat.roomId === this.props.roomId) { @@ -467,7 +474,7 @@ export default class MemberList extends React.Component { const AccessibleButton = sdk.getComponent("elements.AccessibleButton"); inviteButton = - + { inviteButtonText } ; } diff --git a/test/components/views/rooms/MemberList-test.js b/test/components/views/rooms/MemberList-test.js index 093e5588d0..50b40dea20 100644 --- a/test/components/views/rooms/MemberList-test.js +++ b/test/components/views/rooms/MemberList-test.js @@ -88,6 +88,7 @@ describe('MemberList', () => { }; memberListRoom.currentState = { members: {}, + getMember: jest.fn(), getStateEvents: (eventType, stateKey) => stateKey === undefined ? [] : null, // ignore 3pid invites }; for (const member of [...adminUsers, ...moderatorUsers, ...defaultUsers]) { diff --git a/test/test-utils.js b/test/test-utils.js index bad3547133..4faf948178 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -246,6 +246,7 @@ export function mkStubRoom(roomId = null) { maySendMessage: jest.fn().mockReturnValue(true), currentState: { getStateEvents: jest.fn(), + getMember: jest.fn(), mayClientSendStateEvent: jest.fn().mockReturnValue(true), maySendStateEvent: jest.fn().mockReturnValue(true), maySendEvent: jest.fn().mockReturnValue(true),