Merge pull request #6061 from jaiwanth-v/update-memberlist-invite

Update MemberList to reflect changes for invite permission change
This commit is contained in:
Michael Telatynski 2021-05-19 17:35:58 +01:00 committed by GitHub
commit aa4984019c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View file

@ -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) { _getMembersState(members) {
// set the state after determining _showPresence to make sure it's // set the state after determining _showPresence to make sure it's
// taken into account while rerendering // taken into account while rerendering
@ -141,6 +147,7 @@ export default class MemberList extends React.Component {
members: members, members: members,
filteredJoinedMembers: this._filterMembers(members, 'join'), filteredJoinedMembers: this._filterMembers(members, 'join'),
filteredInvitedMembers: this._filterMembers(members, 'invite'), filteredInvitedMembers: this._filterMembers(members, 'invite'),
canInvite: this.canInvite,
// ideally we'd size this to the page height, but // ideally we'd size this to the page height, but
// in practice I find that a little constraining // 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") { event.getType() === "m.room.third_party_invite") {
this._updateList(); this._updateList();
} }
if (this.canInvite !== this.state.canInvite) this.setState({ canInvite: this.canInvite });
}; };
_updateList = rate_limited_func(() => { _updateList = rate_limited_func(() => {
@ -455,8 +464,6 @@ export default class MemberList extends React.Component {
let inviteButton; let inviteButton;
if (room && room.getMyMembership() === 'join') { if (room && room.getMyMembership() === 'join') {
const canInvite = room.canInvite(cli.getUserId());
let inviteButtonText = _t("Invite to this room"); let inviteButtonText = _t("Invite to this room");
const chat = CommunityPrototypeStore.instance.getSelectedCommunityGeneralChat(); const chat = CommunityPrototypeStore.instance.getSelectedCommunityGeneralChat();
if (chat && chat.roomId === this.props.roomId) { if (chat && chat.roomId === this.props.roomId) {
@ -467,7 +474,7 @@ export default class MemberList extends React.Component {
const AccessibleButton = sdk.getComponent("elements.AccessibleButton"); const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
inviteButton = inviteButton =
<AccessibleButton className="mx_MemberList_invite" onClick={this.onInviteButtonClick} disabled={!canInvite}> <AccessibleButton className="mx_MemberList_invite" onClick={this.onInviteButtonClick} disabled={!this.state.canInvite}>
<span>{ inviteButtonText }</span> <span>{ inviteButtonText }</span>
</AccessibleButton>; </AccessibleButton>;
} }

View file

@ -88,6 +88,7 @@ describe('MemberList', () => {
}; };
memberListRoom.currentState = { memberListRoom.currentState = {
members: {}, members: {},
getMember: jest.fn(),
getStateEvents: (eventType, stateKey) => stateKey === undefined ? [] : null, // ignore 3pid invites getStateEvents: (eventType, stateKey) => stateKey === undefined ? [] : null, // ignore 3pid invites
}; };
for (const member of [...adminUsers, ...moderatorUsers, ...defaultUsers]) { for (const member of [...adminUsers, ...moderatorUsers, ...defaultUsers]) {

View file

@ -246,6 +246,7 @@ export function mkStubRoom(roomId = null) {
maySendMessage: jest.fn().mockReturnValue(true), maySendMessage: jest.fn().mockReturnValue(true),
currentState: { currentState: {
getStateEvents: jest.fn(), getStateEvents: jest.fn(),
getMember: jest.fn(),
mayClientSendStateEvent: jest.fn().mockReturnValue(true), mayClientSendStateEvent: jest.fn().mockReturnValue(true),
maySendStateEvent: jest.fn().mockReturnValue(true), maySendStateEvent: jest.fn().mockReturnValue(true),
maySendEvent: jest.fn().mockReturnValue(true), maySendEvent: jest.fn().mockReturnValue(true),