From 4df16e82456fc908b5f0ccd43438b62d6f8e390d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 14 Sep 2017 12:51:53 -0600 Subject: [PATCH 01/12] Display which users are ignored in the user settings Adds https://github.com/vector-im/riot-web/issues/1767 Signed-off-by: Travis Ralston --- src/components/structures/UserSettings.js | 17 +++++++++++++++++ src/i18n/strings/en_EN.json | 1 + src/i18n/strings/en_US.json | 1 + 3 files changed, 19 insertions(+) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index e67991ac12..6c87c6fe0a 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -796,6 +796,22 @@ module.exports = React.createClass({ ); }, + _renderIgnoredUsers: function() { + let ignoredUsers = MatrixClientPeg.get().getIgnoredUsers(); + if (ignoredUsers.length > 0) { + return ( +
+

{ _t("Ignored Users") }

+
+
    + {ignoredUsers.map(u => (
  • {u}
  • ))} +
+
+
+ ); + } else return (
); + }, + _renderLocalSetting: function(setting) { // TODO: this ought to be a separate component so that we don't need // to rebind the onChange each time we render @@ -1302,6 +1318,7 @@ module.exports = React.createClass({ {this._renderWebRtcSettings()} {this._renderDevicesPanel()} {this._renderCryptoInfo()} + {this._renderIgnoredUsers()} {this._renderBulkOptions()} {this._renderBugReport()} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index de0b8e9ebb..ae98535e51 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -264,6 +264,7 @@ "Kick": "Kick", "Kicks user with given id": "Kicks user with given id", "Labs": "Labs", + "Ignored Users": "Ignored Users", "Last seen": "Last seen", "Leave room": "Leave room", "left and rejoined": "left and rejoined", diff --git a/src/i18n/strings/en_US.json b/src/i18n/strings/en_US.json index dd94a82727..5870fe67f3 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -231,6 +231,7 @@ "Kick": "Kick", "Kicks user with given id": "Kicks user with given id", "Labs": "Labs", + "Ignored Users": "Ignored Users", "Leave room": "Leave room", "left and rejoined": "left and rejoined", "left": "left", From 4579d20fd0f0bdb390ddcd8aaa7d558b087165de Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 14 Sep 2017 15:33:36 -0600 Subject: [PATCH 02/12] Unignore people from the settings Signed-off-by: Travis Ralston --- src/components/structures/UserSettings.js | 58 +++++++++++++++++++++-- src/i18n/strings/en_EN.json | 1 + src/i18n/strings/en_US.json | 1 + 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 6c87c6fe0a..966e3cffbb 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -172,6 +172,42 @@ const THEMES = [ }, ]; +const IgnoredUser = React.createClass({ + propTypes: { + userId: React.PropTypes.string.isRequired, + onUnignored: React.PropTypes.func.isRequired, + }, + + _onUnignoreClick: function() { + const ignoredUsers = MatrixClientPeg.get().getIgnoredUsers(); + const index = ignoredUsers.indexOf(this.props.userId); + if (index !== -1) { + ignoredUsers.splice(index, 1); + MatrixClientPeg.get().setIgnoredUsers(ignoredUsers) + .then(() => this.props.onUnignored(this.props.userId)); + } else this.props.onUnignored(this.props.userId); + }, + + render: function() { + let unbanButton; + + if (this.props.canUnban) { + unbanButton = + { _t('Unban') } + ; + } + + return ( +
  • + + { _t("Unignore") } + + { this.props.userId } +
  • + ); + }, +}); + module.exports = React.createClass({ displayName: 'UserSettings', @@ -207,6 +243,7 @@ module.exports = React.createClass({ vectorVersion: undefined, rejectingInvites: false, mediaDevices: null, + ignoredUsers: [] }; }, @@ -228,6 +265,7 @@ module.exports = React.createClass({ } this._refreshMediaDevices(); + this._refreshIgnoredUsers(); // Bulk rejecting invites: // /sync won't have had time to return when UserSettings re-renders from state changes, so getRooms() @@ -346,6 +384,18 @@ module.exports = React.createClass({ }); }, + _refreshIgnoredUsers: function(userIdUnignored=null) { + let users = MatrixClientPeg.get().getIgnoredUsers(); + if (userIdUnignored) { + var index = users.indexOf(userIdUnignored); + if (index !== -1) users.splice(index, 1); + } + console.log("Updating ignored users: "+JSON.stringify(users)); + this.setState({ + ignoredUsers: users + }); + }, + onAction: function(payload) { if (payload.action === "notifier_enabled") { this.forceUpdate(); @@ -797,14 +847,16 @@ module.exports = React.createClass({ }, _renderIgnoredUsers: function() { - let ignoredUsers = MatrixClientPeg.get().getIgnoredUsers(); - if (ignoredUsers.length > 0) { + if (this.state.ignoredUsers.length > 0) { + let updateHandler = this._refreshIgnoredUsers; return (

    { _t("Ignored Users") }

      - {ignoredUsers.map(u => (
    • {u}
    • ))} + {this.state.ignoredUsers.map(function(userId) { + return (); + })}
    diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index ae98535e51..57870a18e4 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -265,6 +265,7 @@ "Kicks user with given id": "Kicks user with given id", "Labs": "Labs", "Ignored Users": "Ignored Users", + "Unignore": "Unignore", "Last seen": "Last seen", "Leave room": "Leave room", "left and rejoined": "left and rejoined", diff --git a/src/i18n/strings/en_US.json b/src/i18n/strings/en_US.json index 5870fe67f3..225d6e28d7 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -232,6 +232,7 @@ "Kicks user with given id": "Kicks user with given id", "Labs": "Labs", "Ignored Users": "Ignored Users", + "Unignore": "Unignore", "Leave room": "Leave room", "left and rejoined": "left and rejoined", "left": "left", From 2bc866b997f0707a6618e118d881908dc16f6abd Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 14 Sep 2017 15:41:12 -0600 Subject: [PATCH 03/12] Clean up UserSettings for linting Signed-off-by: Travis Ralston --- src/components/structures/UserSettings.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 966e3cffbb..3060f50987 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -189,14 +189,6 @@ const IgnoredUser = React.createClass({ }, render: function() { - let unbanButton; - - if (this.props.canUnban) { - unbanButton = - { _t('Unban') } - ; - } - return (
  • @@ -243,7 +235,7 @@ module.exports = React.createClass({ vectorVersion: undefined, rejectingInvites: false, mediaDevices: null, - ignoredUsers: [] + ignoredUsers: [], }; }, @@ -385,14 +377,13 @@ module.exports = React.createClass({ }, _refreshIgnoredUsers: function(userIdUnignored=null) { - let users = MatrixClientPeg.get().getIgnoredUsers(); + const users = MatrixClientPeg.get().getIgnoredUsers(); if (userIdUnignored) { - var index = users.indexOf(userIdUnignored); + const index = users.indexOf(userIdUnignored); if (index !== -1) users.splice(index, 1); } - console.log("Updating ignored users: "+JSON.stringify(users)); this.setState({ - ignoredUsers: users + ignoredUsers: users, }); }, @@ -848,14 +839,16 @@ module.exports = React.createClass({ _renderIgnoredUsers: function() { if (this.state.ignoredUsers.length > 0) { - let updateHandler = this._refreshIgnoredUsers; + const updateHandler = this._refreshIgnoredUsers; return (

    { _t("Ignored Users") }

      {this.state.ignoredUsers.map(function(userId) { - return (); + return (); })}
    From 2d517079d9d9f9e5510ac53133e917ddfaf77719 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 14 Sep 2017 16:08:51 -0600 Subject: [PATCH 04/12] Add unresponsive /ignore and /unignore commands Signed-off-by: Travis Ralston --- src/SlashCommands.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/SlashCommands.js b/src/SlashCommands.js index e5378d4347..b72ea341b5 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -240,6 +240,35 @@ const commands = { return reject(this.getUsage()); }), + ignore: new Command("ignore", "", function(roomId, args) { + if (args) { + const matches = args.match(/^(\S+)$/); + if (matches) { + const ignoredUsers = MatrixClientPeg.get().getIgnoredUsers(); + ignoredUsers.push(matches[1]); // de-duped internally below + return success( + MatrixClientPeg.get().setIgnoredUsers(ignoredUsers), + ); + } + } + return reject(this.getUsage()); + }), + + unignore: new Command("unignore", "", function(roomId, args) { + if (args) { + const matches = args.match(/^(\S+)$/); + if (matches) { + const ignoredUsers = MatrixClientPeg.get().getIgnoredUsers(); + const index = ignoredUsers.indexOf(matches[1]); + if (index !== -1) ignoredUsers.splice(index, 1); + return success( + MatrixClientPeg.get().setIgnoredUsers(ignoredUsers), + ); + } + } + return reject(this.getUsage()); + }), + // Define the power level of a user op: new Command("op", " []", function(roomId, args) { if (args) { From 13a251e29cfbee4fa615bff9a3f94183c722461c Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 14 Sep 2017 16:21:36 -0600 Subject: [PATCH 05/12] Give feedback for /ignore and /unignore Signed-off-by: Travis Ralston --- src/SlashCommands.js | 32 ++++++++++++++++++++++++++++---- src/i18n/strings/en_EN.json | 4 ++++ src/i18n/strings/en_US.json | 4 ++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/SlashCommands.js b/src/SlashCommands.js index b72ea341b5..a7551a789c 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -244,10 +244,22 @@ const commands = { if (args) { const matches = args.match(/^(\S+)$/); if (matches) { + const userId = matches[1]; const ignoredUsers = MatrixClientPeg.get().getIgnoredUsers(); - ignoredUsers.push(matches[1]); // de-duped internally below + ignoredUsers.push(userId); // de-duped internally below return success( - MatrixClientPeg.get().setIgnoredUsers(ignoredUsers), + MatrixClientPeg.get().setIgnoredUsers(ignoredUsers).then(() => { + const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + Modal.createTrackedDialog('Slash Commands', 'User ignored', QuestionDialog, { + title: _t("Ignored user"), + description: ( +
    +

    {_t("You are now ignoring %(userId)s", {userId: userId})}

    +
    + ), + hasCancelButton: false, + }); + }), ); } } @@ -258,11 +270,23 @@ const commands = { if (args) { const matches = args.match(/^(\S+)$/); if (matches) { + const userId = matches[1]; const ignoredUsers = MatrixClientPeg.get().getIgnoredUsers(); - const index = ignoredUsers.indexOf(matches[1]); + const index = ignoredUsers.indexOf(userId); if (index !== -1) ignoredUsers.splice(index, 1); return success( - MatrixClientPeg.get().setIgnoredUsers(ignoredUsers), + MatrixClientPeg.get().setIgnoredUsers(ignoredUsers).then(() => { + const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + Modal.createTrackedDialog('Slash Commands', 'User unignored', QuestionDialog, { + title: _t("Unignored user"), + description: ( +
    +

    {_t("You are no longer ignoring %(userId)s", {userId: userId})}

    +
    + ), + hasCancelButton: false, + }); + }), ); } } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 57870a18e4..9b3135fa07 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -266,6 +266,10 @@ "Labs": "Labs", "Ignored Users": "Ignored Users", "Unignore": "Unignore", + "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", + "Ignored user": "Ignored user", "Last seen": "Last seen", "Leave room": "Leave room", "left and rejoined": "left and rejoined", diff --git a/src/i18n/strings/en_US.json b/src/i18n/strings/en_US.json index 225d6e28d7..7051967abc 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -233,6 +233,10 @@ "Labs": "Labs", "Ignored Users": "Ignored Users", "Unignore": "Unignore", + "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", + "Ignored user": "Ignored user", "Leave room": "Leave room", "left and rejoined": "left and rejoined", "left": "left", From 3889df6b081f0b3b489f96f99ad25cf88c784a44 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 14 Sep 2017 17:10:02 -0600 Subject: [PATCH 06/12] 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", From 2e72d6cd7c687f84740e251b4e67fe9d097ac9af Mon Sep 17 00:00:00 2001 From: turt2live Date: Thu, 14 Sep 2017 20:16:56 -0600 Subject: [PATCH 07/12] Hide events that were sent by ignored users This code only kicks in if the user was ignored after an event was sent. The homeserver should prevent other events from coming in. Signed-off-by: Travis Ralston --- src/components/structures/LoggedInView.js | 3 +++ src/components/structures/MessagePanel.js | 4 ++++ src/components/structures/TimelinePanel.js | 3 +++ src/components/views/rooms/MemberInfo.js | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/structures/LoggedInView.js b/src/components/structures/LoggedInView.js index 147707b6fc..6adea56a23 100644 --- a/src/components/structures/LoggedInView.js +++ b/src/components/structures/LoggedInView.js @@ -131,6 +131,9 @@ export default React.createClass({ useCompactLayout: event.getContent().useCompactLayout, }); } + if (event.getType() === "m.ignored_user_list") { + dis.dispatch({action: "ignore_state_changed"}); + } }, _onKeyDown: function(ev) { diff --git a/src/components/structures/MessagePanel.js b/src/components/structures/MessagePanel.js index e5884973c6..6cb075183d 100644 --- a/src/components/structures/MessagePanel.js +++ b/src/components/structures/MessagePanel.js @@ -241,6 +241,10 @@ module.exports = React.createClass({ // TODO: Implement granular (per-room) hide options _shouldShowEvent: function(mxEv) { + if (MatrixClientPeg.get().isUserIgnored(mxEv.sender.userId)) { + return false; // ignored = no show (only happens if the ignore happens after an event was received) + } + const EventTile = sdk.getComponent('rooms.EventTile'); if (!EventTile.haveTileForEvent(mxEv)) { return false; // no tile = no show diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index 862c3f46d0..c4723f515d 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -384,6 +384,9 @@ var TimelinePanel = React.createClass({ this.sendReadReceipt(); this.updateReadMarker(); break; + case 'ignore_state_changed': + this.forceUpdate(); + break; } }, diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js index b9324249e9..e21fd22e64 100644 --- a/src/components/views/rooms/MemberInfo.js +++ b/src/components/views/rooms/MemberInfo.js @@ -115,7 +115,7 @@ module.exports = withMatrixClient(React.createClass({ }, _checkIgnoreState: function() { - const isIgnoring = this.props.matrixClient.getIgnoredUsers().indexOf(this.props.member.userId) !== -1; + const isIgnoring = this.props.matrixClient.isUserIgnored(this.props.member.userId); this.setState({isIgnoring: isIgnoring}); }, From 6e00f703203a6ed8046c3ed676f41678f809710c Mon Sep 17 00:00:00 2001 From: turt2live Date: Thu, 14 Sep 2017 20:25:02 -0600 Subject: [PATCH 08/12] Hide read receipts and typing notifs for ignored users Signed-off-by: Travis Ralston --- src/WhoIsTyping.js | 6 ++++++ src/components/structures/MessagePanel.js | 3 +++ src/components/structures/RoomStatusBar.js | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/WhoIsTyping.js b/src/WhoIsTyping.js index f3d89f0ff2..2a12703a27 100644 --- a/src/WhoIsTyping.js +++ b/src/WhoIsTyping.js @@ -18,6 +18,12 @@ var MatrixClientPeg = require("./MatrixClientPeg"); import { _t } from './languageHandler'; module.exports = { + usersTypingApartFromMeAndIgnored: function(room) { + return this.usersTyping( + room, [MatrixClientPeg.get().credentials.userId].concat(MatrixClientPeg.get().getIgnoredUsers()) + ); + }, + usersTypingApartFromMe: function(room) { return this.usersTyping( room, [MatrixClientPeg.get().credentials.userId] diff --git a/src/components/structures/MessagePanel.js b/src/components/structures/MessagePanel.js index 6cb075183d..0124f5d65e 100644 --- a/src/components/structures/MessagePanel.js +++ b/src/components/structures/MessagePanel.js @@ -553,6 +553,9 @@ module.exports = React.createClass({ if (!r.userId || r.type !== "m.read" || r.userId === myUserId) { return; // ignore non-read receipts and receipts from self. } + if (MatrixClientPeg.get().isUserIgnored(r.userId)) { + return; // ignore ignored users + } let member = room.getMember(r.userId); if (!member) { return; // ignore unknown user IDs diff --git a/src/components/structures/RoomStatusBar.js b/src/components/structures/RoomStatusBar.js index 2a81605a78..68b7249d3b 100644 --- a/src/components/structures/RoomStatusBar.js +++ b/src/components/structures/RoomStatusBar.js @@ -121,7 +121,7 @@ module.exports = React.createClass({ onRoomMemberTyping: function(ev, member) { this.setState({ - usersTyping: WhoIsTyping.usersTypingApartFromMe(this.props.room), + usersTyping: WhoIsTyping.usersTypingApartFromMeAndIgnored(this.props.room), }); }, From 3c71898237ecb3d5750c72ef0e12fd766e907a0a Mon Sep 17 00:00:00 2001 From: turt2live Date: Thu, 14 Sep 2017 20:30:40 -0600 Subject: [PATCH 09/12] Add /(un)ignore to autocomplete Signed-off-by: Travis Ralston --- src/autocomplete/CommandProvider.js | 10 ++++++++++ src/i18n/strings/en_EN.json | 2 ++ src/i18n/strings/en_US.json | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/autocomplete/CommandProvider.js b/src/autocomplete/CommandProvider.js index 6f2f68b121..ce1be44b41 100644 --- a/src/autocomplete/CommandProvider.js +++ b/src/autocomplete/CommandProvider.js @@ -94,6 +94,16 @@ const COMMANDS = [ args: ' ', description: 'Verifies a user, device, and pubkey tuple', }, + { + command: '/ignore', + args: '', + description: 'Ignores a user, hiding their messages from you' + }, + { + command: '/unignore', + args: '', + description: 'Stops ignoring a user, showing their messages going forward' + }, // Omitting `/markdown` as it only seems to apply to OldComposer ]; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index f335241ab3..0b582a1f1b 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -272,6 +272,8 @@ "You are no longer ignoring %(userId)s": "You are no longer ignoring %(userId)s", "Unignored user": "Unignored user", "Ignored user": "Ignored user", + "Stops ignoring a user, showing their messages going forward": "Stops ignoring a user, showing their messages going forward", + "Ignores a user, hiding their messages from you": "Ignores a user, hiding their messages from you", "Last seen": "Last seen", "Leave room": "Leave room", "left and rejoined": "left and rejoined", diff --git a/src/i18n/strings/en_US.json b/src/i18n/strings/en_US.json index 48213d354a..c24784d136 100644 --- a/src/i18n/strings/en_US.json +++ b/src/i18n/strings/en_US.json @@ -239,6 +239,8 @@ "You are no longer ignoring %(userId)s": "You are no longer ignoring %(userId)s", "Unignored user": "Unignored user", "Ignored user": "Ignored user", + "Stops ignoring a user, showing their messages going forward": "Stops ignoring a user, showing their messages going forward", + "Ignores a user, hiding their messages from you": "Ignores a user, hiding their messages from you", "Leave room": "Leave room", "left and rejoined": "left and rejoined", "left": "left", From 0363f73e28cb15784cc63e6b4e4316227ea08d07 Mon Sep 17 00:00:00 2001 From: turt2live Date: Thu, 14 Sep 2017 20:47:24 -0600 Subject: [PATCH 10/12] Fix the MessagePanel test Signed-off-by: Travis Ralston --- src/autocomplete/CommandProvider.js | 4 ++-- src/components/structures/MessagePanel.js | 2 +- test/components/structures/MessagePanel-test.js | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/autocomplete/CommandProvider.js b/src/autocomplete/CommandProvider.js index ce1be44b41..011ad0a7dc 100644 --- a/src/autocomplete/CommandProvider.js +++ b/src/autocomplete/CommandProvider.js @@ -97,12 +97,12 @@ const COMMANDS = [ { command: '/ignore', args: '', - description: 'Ignores a user, hiding their messages from you' + description: 'Ignores a user, hiding their messages from you', }, { command: '/unignore', args: '', - description: 'Stops ignoring a user, showing their messages going forward' + description: 'Stops ignoring a user, showing their messages going forward', }, // Omitting `/markdown` as it only seems to apply to OldComposer ]; diff --git a/src/components/structures/MessagePanel.js b/src/components/structures/MessagePanel.js index 0124f5d65e..ff0be6d7fe 100644 --- a/src/components/structures/MessagePanel.js +++ b/src/components/structures/MessagePanel.js @@ -241,7 +241,7 @@ module.exports = React.createClass({ // TODO: Implement granular (per-room) hide options _shouldShowEvent: function(mxEv) { - if (MatrixClientPeg.get().isUserIgnored(mxEv.sender.userId)) { + if (mxEv.sender && MatrixClientPeg.get().isUserIgnored(mxEv.sender.userId)) { return false; // ignored = no show (only happens if the ignore happens after an event was received) } diff --git a/test/components/structures/MessagePanel-test.js b/test/components/structures/MessagePanel-test.js index ad7d9c15c7..8254dd4126 100644 --- a/test/components/structures/MessagePanel-test.js +++ b/test/components/structures/MessagePanel-test.js @@ -24,6 +24,7 @@ var sdk = require('matrix-react-sdk'); var MessagePanel = sdk.getComponent('structures.MessagePanel'); import UserSettingsStore from '../../../src/UserSettingsStore'; +import MatrixClientPeg from '../../../src/MatrixClientPeg'; var test_utils = require('test-utils'); var mockclock = require('mock-clock'); @@ -51,16 +52,19 @@ describe('MessagePanel', function () { var clock = mockclock.clock(); var realSetTimeout = window.setTimeout; var events = mkEvents(); + var sandbox = null; beforeEach(function() { test_utils.beforeEach(this); - client = test_utils.createTestClient(); + sandbox = test_utils.stubClient(); + client = MatrixClientPeg.get(); client.credentials = {userId: '@me:here'}; UserSettingsStore.getSyncedSettings = sinon.stub().returns({}); }); afterEach(function() { clock.uninstall(); + sandbox.restore(); }); function mkEvents() { From 9e77d1b763c2634087e3d06e6b0edb9e6bd9e53d Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 17 Sep 2017 21:50:24 +0100 Subject: [PATCH 11/12] tweak comment --- src/SlashCommands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SlashCommands.js b/src/SlashCommands.js index a7551a789c..5939ceb98e 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -246,7 +246,7 @@ const commands = { if (matches) { const userId = matches[1]; const ignoredUsers = MatrixClientPeg.get().getIgnoredUsers(); - ignoredUsers.push(userId); // de-duped internally below + ignoredUsers.push(userId); // de-duped internally in the js-sdk return success( MatrixClientPeg.get().setIgnoredUsers(ignoredUsers).then(() => { const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); From 2605004edb5b1c69f3047fbd0c170834a1f7b2c8 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 17 Sep 2017 15:04:03 -0600 Subject: [PATCH 12/12] Update ignored users when js-sdk on UserSettings on change Signed-off-by: Travis Ralston --- 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 3060f50987..afcc3e5ce1 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -390,6 +390,8 @@ module.exports = React.createClass({ onAction: function(payload) { if (payload.action === "notifier_enabled") { this.forceUpdate(); + } else if (payload.action === "ignore_state_changed") { + this._refreshIgnoredUsers(); } },