mirror of https://github.com/vector-im/riot-web
Implement bulk invite rejects
parent
1d4591ce68
commit
13dfe9ef0f
|
@ -61,6 +61,7 @@ module.exports = React.createClass({
|
|||
phase: "UserSettings.LOADING", // LOADING, DISPLAY
|
||||
email_add_pending: false,
|
||||
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({
|
||||
action: 'ui_opacity',
|
||||
sideOpacity: 0.3,
|
||||
|
@ -101,6 +108,7 @@ module.exports = React.createClass({
|
|||
middleOpacity: 1.0,
|
||||
});
|
||||
dis.unregister(this.dispatcherRef);
|
||||
MatrixClientPeg.get().removeListener("RoomMember.membership", this._onInviteStateChange);
|
||||
},
|
||||
|
||||
_refreshFromServer: function() {
|
||||
|
@ -280,8 +288,27 @@ module.exports = React.createClass({
|
|||
Modal.createDialog(DeactivateAccountDialog, {});
|
||||
},
|
||||
|
||||
_onRejectAllInvitesClicked: function() {
|
||||
console.log("yup");
|
||||
_onInviteStateChange: function(event, member, oldMembership) {
|
||||
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() {
|
||||
|
@ -429,13 +456,23 @@ module.exports = React.createClass({
|
|||
if (invitedRooms.length === 0) {
|
||||
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>
|
||||
<h3>Bulk Options</h3>
|
||||
<div className="mx_UserSettings_section">
|
||||
<button className="mx_UserSettings_button danger"
|
||||
onClick={this._onRejectAllInvitesClicked}>
|
||||
Reject all {invitedRooms.length} invites
|
||||
</button>
|
||||
{reject}
|
||||
</div>
|
||||
</div>;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue