diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js
index a33095b8e8..6454515c29 100644
--- a/src/components/structures/UserSettings.js
+++ b/src/components/structures/UserSettings.js
@@ -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 =