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 829
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
+48
−19
Merged
Changes from 1 commit
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 |
---|---|---|
|
@@ -29,6 +29,10 @@ import { SettingLevel } from "../../../../../settings/SettingLevel"; | |
import SecureBackupPanel from "../../SecureBackupPanel"; | ||
import SettingsStore from "../../../../../settings/SettingsStore"; | ||
import { UIFeature } from "../../../../../settings/UIFeature"; | ||
import { ListNotificationState } from '../../../../../stores/notifications/ListNotificationState'; | ||
import { RoomNotificationStateStore } from '../../../../../stores/notifications/RoomNotificationStateStore'; | ||
import { DefaultTagID } from '../../../../../stores/room-list/models'; | ||
import { NOTIFICATION_STATE_UPDATE } from '../../../../../stores/notifications/NotificationState'; | ||
import E2eAdvancedPanel, { isE2eAdvancedPanelPossible } from "../../E2eAdvancedPanel"; | ||
import CountlyAnalytics from "../../../../../CountlyAnalytics"; | ||
import { replaceableComponent } from "../../../../../utils/replaceableComponent"; | ||
|
@@ -82,18 +86,19 @@ interface IState { | |
@replaceableComponent("views.settings.tabs.user.SecurityUserSettingsTab") | ||
export default class SecurityUserSettingsTab extends React.Component<IProps, IState> { | ||
private dispatcherRef: string; | ||
private notificationState: ListNotificationState; | ||
|
||
constructor(props: IProps) { | ||
super(props); | ||
|
||
// Get number of rooms we're invited to | ||
const invitedRooms = this.getInvitedRooms(); | ||
this.notificationState = RoomNotificationStateStore.instance.getListState(DefaultTagID.Invite); | ||
|
||
this.state = { | ||
ignoredUserIds: MatrixClientPeg.get().getIgnoredUsers(), | ||
waitingUnignored: [], | ||
managingInvites: false, | ||
invitedRoomAmt: invitedRooms.length, | ||
invitedRoomAmt: this.notificationState.count, | ||
}; | ||
} | ||
|
||
|
@@ -107,10 +112,12 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
|
||
public componentDidMount(): void { | ||
this.dispatcherRef = dis.register(this.onAction); | ||
this.notificationState.on(NOTIFICATION_STATE_UPDATE, this.onNotificationUpdate); | ||
} | ||
|
||
public componentWillUnmount(): void { | ||
dis.unregister(this.dispatcherRef); | ||
this.notificationState.off(NOTIFICATION_STATE_UPDATE, this.onNotificationUpdate); | ||
} | ||
|
||
private updateAnalytics = (checked: boolean): void => { | ||
|
@@ -119,6 +126,10 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
PosthogAnalytics.instance.updateAnonymityFromSettings(MatrixClientPeg.get().getUserId()); | ||
}; | ||
|
||
private onNotificationUpdate = () => { | ||
this.setState({ invitedRoomAmt: this.notificationState.count }); | ||
}; | ||
|
||
private onGoToUserProfileClick = (): void => { | ||
dis.dispatch({ | ||
action: 'view_user_info', | ||
|
@@ -162,10 +173,7 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
const roomId = invitedRoomIds[i]; | ||
|
||
// Accept/reject invite | ||
await action(roomId).then(() => { | ||
// No error, update invited rooms button | ||
this.setState({ invitedRoomAmt: this.state.invitedRoomAmt - 1 }); | ||
}, async (e) => { | ||
await action(roomId).catch(async (e) => { | ||
// Action failure | ||
if (e.errcode === "M_LIMIT_EXCEEDED") { | ||
// Add a delay between each invite change in order to avoid rate | ||
|
@@ -225,9 +233,8 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt | |
return null; | ||
} | ||
|
||
const invitedRooms = this.getInvitedRooms(); | ||
const onClickAccept = this.onAcceptAllInvitesClicked.bind(this, invitedRooms); | ||
const onClickReject = this.onRejectAllInvitesClicked.bind(this, invitedRooms); | ||
const onClickAccept = this.onAcceptAllInvitesClicked.bind(this); | ||
const onClickReject = this.onRejectAllInvitesClicked.bind(this); | ||
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. Could we avoid this? |
||
return ( | ||
<div className='mx_SettingsTab_section mx_SecurityUserSettingsTab_bulkOptions'> | ||
<span className='mx_SettingsTab_subheading'>{ _t('Bulk options') }</span> | ||
|
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.
TBCH, using the
RoomNotificationStateStore
for this feels a little oddThere 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.
That's true, maybe
RoomListStore
would be more logical here?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.
Probably, though I think it might be best to use the js-sdk directly (though you would need to filter out spaces), other people might view this differently