Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix bulk invite button getting a negative count #7122

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Copy link
Contributor

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 odd

Copy link
Contributor Author

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?

Copy link
Contributor

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


this.state = {
ignoredUserIds: MatrixClientPeg.get().getIgnoredUsers(),
waitingUnignored: [],
managingInvites: false,
invitedRoomAmt: invitedRooms.length,
invitedRoomAmt: this.notificationState.count,
};
}

Expand All @@ -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 => {
Expand All @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Expand Down