From 3889df6b081f0b3b489f96f99ad25cf88c784a44 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 14 Sep 2017 17:10:02 -0600 Subject: [PATCH] Add (un)ignore button to MemberInfo Signed-off-by: Travis Ralston --- src/components/views/rooms/MemberInfo.js | 45 ++++++++++++++++++++++++ src/i18n/strings/en_EN.json | 2 ++ src/i18n/strings/en_US.json | 2 ++ 3 files changed, 49 insertions(+) diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js index 64eeddb406..b9324249e9 100644 --- a/src/components/views/rooms/MemberInfo.js +++ b/src/components/views/rooms/MemberInfo.js @@ -62,6 +62,7 @@ module.exports = withMatrixClient(React.createClass({ updating: 0, devicesLoading: true, devices: null, + isIgnoring: false, }; }, @@ -81,6 +82,8 @@ module.exports = withMatrixClient(React.createClass({ cli.on("RoomState.events", this.onRoomStateEvents); cli.on("RoomMember.name", this.onRoomMemberName); cli.on("accountData", this.onAccountData); + + this._checkIgnoreState(); }, componentDidMount: function() { @@ -111,6 +114,11 @@ module.exports = withMatrixClient(React.createClass({ } }, + _checkIgnoreState: function() { + const isIgnoring = this.props.matrixClient.getIgnoredUsers().indexOf(this.props.member.userId) !== -1; + this.setState({isIgnoring: isIgnoring}); + }, + _disambiguateDevices: function(devices) { var names = Object.create(null); for (var i = 0; i < devices.length; i++) { @@ -225,6 +233,18 @@ module.exports = withMatrixClient(React.createClass({ }); }, + onIgnoreToggle: function() { + const ignoredUsers = this.props.matrixClient.getIgnoredUsers(); + if (this.state.isIgnoring) { + const index = ignoredUsers.indexOf(this.props.member.userId); + if (index !== -1) ignoredUsers.splice(index, 1); + } else { + ignoredUsers.push(this.props.member.userId); + } + + this.props.matrixClient.setIgnoredUsers(ignoredUsers).then(() => this.setState({isIgnoring: !this.state.isIgnoring})); + }, + onKick: function() { const membership = this.props.member.membership; const kickLabel = membership === "invite" ? _t("Disinvite") : _t("Kick"); @@ -607,6 +627,29 @@ module.exports = withMatrixClient(React.createClass({ ); }, + _renderUserOptions: function() { + // Only allow the user to ignore the user if its not ourselves + let ignoreButton = null; + if (this.props.member.userId !== this.props.matrixClient.getUserId()) { + ignoreButton = ( + + {this.state.isIgnoring ? _t("Unignore") : _t("Ignore")} + + ); + } + + if (!ignoreButton) return null; + + return ( +
+

{ _t("User Options") }

+
+ {ignoreButton} +
+
+ ); + }, + render: function() { var startChat, kickButton, banButton, muteButton, giveModButton, spinner; if (this.props.member.userId !== this.props.matrixClient.credentials.userId) { @@ -756,6 +799,8 @@ module.exports = withMatrixClient(React.createClass({ + { this._renderUserOptions() } + { adminTools } { startChat } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 9b3135fa07..f335241ab3 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -265,7 +265,9 @@ "Kicks user with given id": "Kicks user with given id", "Labs": "Labs", "Ignored Users": "Ignored Users", + "Ignore": "Ignore", "Unignore": "Unignore", + "User Options": "User Options", "You are now ignoring %(userId)s": "You are now ignoring %(userId)s", "You are no longer ignoring %(userId)s": "You are no longer ignoring %(userId)s", "Unignored user": "Unignored user", diff --git a/src/i18n/strings/en_US.json b/src/i18n/strings/en_US.json index 7051967abc..48213d354a 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -232,7 +232,9 @@ "Kicks user with given id": "Kicks user with given id", "Labs": "Labs", "Ignored Users": "Ignored Users", + "Ignore": "Ignore", "Unignore": "Unignore", + "User Options": "User Options", "You are now ignoring %(userId)s": "You are now ignoring %(userId)s", "You are no longer ignoring %(userId)s": "You are no longer ignoring %(userId)s", "Unignored user": "Unignored user",