This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Fix bulk invite button getting a negative count #7122
Merged
dbkr
merged 4 commits into
matrix-org:develop
from
renancleyson-dev:fix-bulk-invites-wrong-counter
Nov 16, 2021
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
85ac644
Fix bulk invite button getting a negative counter
renancleyson-dev c270b92
Change invites to be count on membership events
renancleyson-dev cafd88e
Remove unnecessary bind
renancleyson-dev ca3944b
Change invitedRooms state to a set of ids
renancleyson-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ interface IState { | |
ignoredUserIds: string[]; | ||
waitingUnignored: string[]; | ||
managingInvites: boolean; | ||
invitedRoomAmt: number; | ||
invitedRooms: Room[]; | ||
} | ||
|
||
@replaceableComponent("views.settings.tabs.user.SecurityUserSettingsTab") | ||
|
@@ -86,14 +86,14 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
constructor(props: IProps) { | ||
super(props); | ||
|
||
// Get number of rooms we're invited to | ||
// Get rooms we're invited to | ||
const invitedRooms = this.getInvitedRooms(); | ||
|
||
this.state = { | ||
ignoredUserIds: MatrixClientPeg.get().getIgnoredUsers(), | ||
waitingUnignored: [], | ||
managingInvites: false, | ||
invitedRoomAmt: invitedRooms.length, | ||
invitedRooms, | ||
}; | ||
} | ||
|
||
|
@@ -107,10 +107,12 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
|
||
public componentDidMount(): void { | ||
this.dispatcherRef = dis.register(this.onAction); | ||
MatrixClientPeg.get().on("Room.myMembership", this.onMyMembership); | ||
} | ||
|
||
public componentWillUnmount(): void { | ||
dis.unregister(this.dispatcherRef); | ||
MatrixClientPeg.get().removeListener("Room.myMembership", this.onMyMembership); | ||
} | ||
|
||
private updateAnalytics = (checked: boolean): void => { | ||
|
@@ -119,6 +121,31 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
PosthogAnalytics.instance.updateAnonymityFromSettings(MatrixClientPeg.get().getUserId()); | ||
}; | ||
|
||
private onMyMembership = (room: Room, membership: string): void => { | ||
const { invitedRooms } = this.state; | ||
|
||
if (room.isSpaceRoom()) { | ||
return; | ||
} | ||
|
||
if (membership === "invite") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we have a membership enum but it might be worth checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't find any membership enum :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, probably don'ŧ worry about it, it should be in the js-sdk, anyway |
||
this.addInvitedRoom(room); | ||
} else if (invitedRooms.some(invitedRoom => invitedRoom.roomId === room.roomId)) { | ||
// The user isn't invited anymore | ||
this.removeInvitedRoom(room.roomId); | ||
} | ||
}; | ||
|
||
private addInvitedRoom = (room: Room): void => { | ||
this.setState(({ invitedRooms }) => ({ invitedRooms: [...invitedRooms, room] })); | ||
}; | ||
|
||
private removeInvitedRoom = (roomId: string): void => { | ||
this.setState((prevState) => ({ | ||
invitedRooms: prevState.invitedRooms.filter(room => room.roomId !== roomId), | ||
})); | ||
}; | ||
|
||
private onGoToUserProfileClick = (): void => { | ||
dis.dispatch({ | ||
action: 'view_user_info', | ||
|
@@ -151,7 +178,7 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
}); | ||
|
||
// Compile array of invitation room ids | ||
const invitedRoomIds = this.getInvitedRooms().map((room) => { | ||
const invitedRoomIds = this.state.invitedRooms.map((room) => { | ||
return room.roomId; | ||
}); | ||
|
||
|
@@ -164,7 +191,7 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
// Accept/reject invite | ||
await action(roomId).then(() => { | ||
// No error, update invited rooms button | ||
this.setState({ invitedRoomAmt: this.state.invitedRoomAmt - 1 }); | ||
this.removeInvitedRoom(roomId); | ||
}, async (e) => { | ||
// Action failure | ||
if (e.errcode === "M_LIMIT_EXCEEDED") { | ||
|
@@ -221,21 +248,20 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
} | ||
|
||
private renderManageInvites(): JSX.Element { | ||
if (this.state.invitedRoomAmt === 0) { | ||
const { invitedRooms } = this.state; | ||
|
||
if (invitedRooms.length === 0) { | ||
return null; | ||
} | ||
|
||
const invitedRooms = this.getInvitedRooms(); | ||
const onClickAccept = this.onAcceptAllInvitesClicked.bind(this, invitedRooms); | ||
const onClickReject = this.onRejectAllInvitesClicked.bind(this, invitedRooms); | ||
return ( | ||
<div className='mx_SettingsTab_section mx_SecurityUserSettingsTab_bulkOptions'> | ||
<span className='mx_SettingsTab_subheading'>{ _t('Bulk options') }</span> | ||
<AccessibleButton onClick={onClickAccept} kind='primary' disabled={this.state.managingInvites}> | ||
{ _t("Accept all %(invitedRooms)s invites", { invitedRooms: this.state.invitedRoomAmt }) } | ||
<AccessibleButton onClick={this.onAcceptAllInvitesClicked} kind='primary' disabled={this.state.managingInvites}> | ||
{ _t("Accept all %(invitedRooms)s invites", { invitedRooms: invitedRooms.length }) } | ||
</AccessibleButton> | ||
<AccessibleButton onClick={onClickReject} kind='danger' disabled={this.state.managingInvites}> | ||
{ _t("Reject all %(invitedRooms)s invites", { invitedRooms: this.state.invitedRoomAmt }) } | ||
<AccessibleButton onClick={this.onRejectAllInvitesClicked} kind='danger' disabled={this.state.managingInvites}> | ||
{ _t("Reject all %(invitedRooms)s invites", { invitedRooms: invitedRooms.length }) } | ||
</AccessibleButton> | ||
{ this.state.managingInvites ? <InlineSpinner /> : <div /> } | ||
</div> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're mainly adding and removing elements of this array, I think it could be better to use a
Set