From 0d8a7eabc7b7cf203d0c3bcdf78ed8583030eddb Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Wed, 19 May 2021 12:38:39 +0530 Subject: [PATCH 1/4] Update MemberList on invite permission change Signed-off-by: Jaiwanth --- src/components/views/rooms/MemberList.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/views/rooms/MemberList.js b/src/components/views/rooms/MemberList.js index fbc0e477a1..bb60c958f7 100644 --- a/src/components/views/rooms/MemberList.js +++ b/src/components/views/rooms/MemberList.js @@ -196,6 +196,9 @@ export default class MemberList extends React.Component { event.getType() === "m.room.third_party_invite") { this._updateList(); } + if (event.getContent().invite !== event.getPrevContent().invite) { + this.forceUpdate(); + } }; _updateList = rate_limited_func(() => { From e78206301fbc1951791b1dbd41693e1feae60244 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Wed, 19 May 2021 14:31:04 +0530 Subject: [PATCH 2/4] Modify to avoid forceUpdate --- src/components/views/rooms/MemberList.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/views/rooms/MemberList.js b/src/components/views/rooms/MemberList.js index bb60c958f7..f991827091 100644 --- a/src/components/views/rooms/MemberList.js +++ b/src/components/views/rooms/MemberList.js @@ -136,11 +136,13 @@ export default class MemberList extends React.Component { _getMembersState(members) { // set the state after determining _showPresence to make sure it's // taken into account while rerendering + const cli = MatrixClientPeg.get(); return { loading: false, members: members, filteredJoinedMembers: this._filterMembers(members, 'join'), filteredInvitedMembers: this._filterMembers(members, 'invite'), + canInvite: cli.getRoom(this.props.roomId).canInvite(cli.getUserId()), // ideally we'd size this to the page height, but // in practice I find that a little constraining @@ -196,9 +198,10 @@ export default class MemberList extends React.Component { event.getType() === "m.room.third_party_invite") { this._updateList(); } - if (event.getContent().invite !== event.getPrevContent().invite) { - this.forceUpdate(); - } + + const cli = MatrixClientPeg.get(); + const canInvite = cli.getRoom(this.props.roomId).canInvite(cli.getUserId()); + if (canInvite !== this.state.canInvite) this.setState({canInvite}); }; _updateList = rate_limited_func(() => { @@ -458,8 +461,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) { @@ -470,7 +471,7 @@ export default class MemberList extends React.Component { const AccessibleButton = sdk.getComponent("elements.AccessibleButton"); inviteButton = - + { inviteButtonText } ; } From 506a798961e36533596593a9338eec0367b7947f Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Wed, 19 May 2021 15:01:05 +0530 Subject: [PATCH 3/4] Add getMember mock --- test/components/views/rooms/MemberList-test.js | 1 + test/test-utils.js | 1 + 2 files changed, 2 insertions(+) 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 953693a820..d7c960228c 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -245,6 +245,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), From d73eb0c70f23b4d54a928db6399d2a855a350654 Mon Sep 17 00:00:00 2001 From: Jaiwanth Date: Wed, 19 May 2021 17:46:10 +0530 Subject: [PATCH 4/4] Update MemberList.js --- src/components/views/rooms/MemberList.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/MemberList.js b/src/components/views/rooms/MemberList.js index f991827091..55fe650b7b 100644 --- a/src/components/views/rooms/MemberList.js +++ b/src/components/views/rooms/MemberList.js @@ -133,16 +133,21 @@ 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 - const cli = MatrixClientPeg.get(); return { loading: false, members: members, filteredJoinedMembers: this._filterMembers(members, 'join'), filteredInvitedMembers: this._filterMembers(members, 'invite'), - canInvite: cli.getRoom(this.props.roomId).canInvite(cli.getUserId()), + canInvite: this.canInvite, // ideally we'd size this to the page height, but // in practice I find that a little constraining @@ -199,9 +204,7 @@ export default class MemberList extends React.Component { this._updateList(); } - const cli = MatrixClientPeg.get(); - const canInvite = cli.getRoom(this.props.roomId).canInvite(cli.getUserId()); - if (canInvite !== this.state.canInvite) this.setState({canInvite}); + if (this.canInvite !== this.state.canInvite) this.setState({ canInvite: this.canInvite }); }; _updateList = rate_limited_func(() => {