From 1d4591ce68624f0a28055e1ffa40b7226ad44f2d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 14 Dec 2016 15:01:50 +0000 Subject: [PATCH 1/5] Add UI in UserSettings for bulk rejecting invites --- src/components/structures/UserSettings.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 49674957bc..a33095b8e8 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -280,6 +280,10 @@ module.exports = React.createClass({ Modal.createDialog(DeactivateAccountDialog, {}); }, + _onRejectAllInvitesClicked: function() { + console.log("yup"); + }, + _renderUserInterfaceSettings: function() { var client = MatrixClientPeg.get(); @@ -418,6 +422,24 @@ module.exports = React.createClass({ ; }, + _renderBulkOptions: function() { + let invitedRooms = MatrixClientPeg.get().getRooms().filter((r) => { + return r.hasMembershipState(this._me, "invite"); + }); + if (invitedRooms.length === 0) { + return null; + } + return
+

Bulk Options

+
+ +
+
; + }, + render: function() { var self = this; var Loader = sdk.getComponent("elements.Spinner"); @@ -580,6 +602,7 @@ module.exports = React.createClass({ {this._renderLabs()} {this._renderDevicesPanel()} {this._renderCryptoInfo()} + {this._renderBulkOptions()}

Advanced

From 13dfe9ef0fee67980633f03b37c273a79964ffb1 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 14 Dec 2016 16:00:50 +0000 Subject: [PATCH 2/5] Implement bulk invite rejects --- src/components/structures/UserSettings.js | 49 ++++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) 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 = ; + if (!this.state.rejectingInvites) { + reject = ( + + ); + } + return

Bulk Options

- + {reject}
; }, From 8f42134d9fa6da65a9dd3fff2103ecbc3ffe4869 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 14 Dec 2016 16:04:20 +0000 Subject: [PATCH 3/5] Explain why binding --- src/components/structures/UserSettings.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 6454515c29..43c60c59da 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -461,6 +461,8 @@ module.exports = React.createClass({ let reject = ; if (!this.state.rejectingInvites) { + // bind() the invited rooms so any new invites that may come in as this button is clicked + // don't inadvertently get rejected as well. reject = (