Implement bulk invite rejects

This commit is contained in:
Kegan Dougal 2016-12-14 16:00:50 +00:00
parent 1d4591ce68
commit 13dfe9ef0f

View file

@ -61,6 +61,7 @@ module.exports = React.createClass({
phase: "UserSettings.LOADING", // LOADING, DISPLAY phase: "UserSettings.LOADING", // LOADING, DISPLAY
email_add_pending: false, email_add_pending: false,
vectorVersion: null, vectorVersion: null,
rejectingInvites: false,
}; };
}, },
@ -80,6 +81,12 @@ module.exports = React.createClass({
}); });
} }
// Bulk rejecting invites:
// /sync won't have had time to return when UserSettings re-renders from state changes, so getRooms()
// will still return rooms with invites. To get around this, add a listener for
// membership updates and kick the UI.
MatrixClientPeg.get().on("RoomMember.membership", this._onInviteStateChange);
dis.dispatch({ dis.dispatch({
action: 'ui_opacity', action: 'ui_opacity',
sideOpacity: 0.3, sideOpacity: 0.3,
@ -101,6 +108,7 @@ module.exports = React.createClass({
middleOpacity: 1.0, middleOpacity: 1.0,
}); });
dis.unregister(this.dispatcherRef); dis.unregister(this.dispatcherRef);
MatrixClientPeg.get().removeListener("RoomMember.membership", this._onInviteStateChange);
}, },
_refreshFromServer: function() { _refreshFromServer: function() {
@ -280,8 +288,27 @@ module.exports = React.createClass({
Modal.createDialog(DeactivateAccountDialog, {}); Modal.createDialog(DeactivateAccountDialog, {});
}, },
_onRejectAllInvitesClicked: function() { _onInviteStateChange: function(event, member, oldMembership) {
console.log("yup"); if (member.userId === this._me && oldMembership === "invite") {
this.forceUpdate();
}
},
_onRejectAllInvitesClicked: function(rooms, ev) {
this.setState({
rejectingInvites: true
});
// reject the invites
let promises = rooms.map((room) => {
return MatrixClientPeg.get().leave(room.roomId);
});
// purposefully drop errors to the floor: we'll just have a non-zero number on the UI
// after trying to reject all the invites.
q.allSettled(promises).then(() => {
this.setState({
rejectingInvites: false
});
});
}, },
_renderUserInterfaceSettings: function() { _renderUserInterfaceSettings: function() {
@ -429,13 +456,23 @@ module.exports = React.createClass({
if (invitedRooms.length === 0) { if (invitedRooms.length === 0) {
return null; return null;
} }
let Spinner = sdk.getComponent("elements.Spinner");
let reject = <Spinner />;
if (!this.state.rejectingInvites) {
reject = (
<button className="mx_UserSettings_button danger"
onClick={this._onRejectAllInvitesClicked.bind(this, invitedRooms)}>
Reject all {invitedRooms.length} invites
</button>
);
}
return <div> return <div>
<h3>Bulk Options</h3> <h3>Bulk Options</h3>
<div className="mx_UserSettings_section"> <div className="mx_UserSettings_section">
<button className="mx_UserSettings_button danger" {reject}
onClick={this._onRejectAllInvitesClicked}>
Reject all {invitedRooms.length} invites
</button>
</div> </div>
</div>; </div>;
}, },