From 11068d189cf03e309cccca75b83ee8674fb01796 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 31 Oct 2019 16:19:42 -0600 Subject: [PATCH] Hide messages blocked by ban lists --- res/css/_components.scss | 1 + res/css/views/messages/_MjolnirBody.scss | 19 ++++++++ src/components/views/messages/MessageEvent.js | 24 +++++++++- src/components/views/messages/MjolnirBody.js | 47 +++++++++++++++++++ src/i18n/strings/en_EN.json | 1 + 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 res/css/views/messages/_MjolnirBody.scss create mode 100644 src/components/views/messages/MjolnirBody.js diff --git a/res/css/_components.scss b/res/css/_components.scss index a0e5881201..788e22a766 100644 --- a/res/css/_components.scss +++ b/res/css/_components.scss @@ -123,6 +123,7 @@ @import "./views/messages/_MTextBody.scss"; @import "./views/messages/_MessageActionBar.scss"; @import "./views/messages/_MessageTimestamp.scss"; +@import "./views/messages/_MjolnirBody.scss"; @import "./views/messages/_ReactionsRow.scss"; @import "./views/messages/_ReactionsRowButton.scss"; @import "./views/messages/_ReactionsRowButtonTooltip.scss"; diff --git a/res/css/views/messages/_MjolnirBody.scss b/res/css/views/messages/_MjolnirBody.scss new file mode 100644 index 0000000000..80be7429e5 --- /dev/null +++ b/res/css/views/messages/_MjolnirBody.scss @@ -0,0 +1,19 @@ +/* +Copyright 2019 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +.mx_MjolnirBody { + opacity: 0.4; +} diff --git a/src/components/views/messages/MessageEvent.js b/src/components/views/messages/MessageEvent.js index a616dd96ed..2e353794d7 100644 --- a/src/components/views/messages/MessageEvent.js +++ b/src/components/views/messages/MessageEvent.js @@ -18,6 +18,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import sdk from '../../../index'; +import SettingsStore from "../../../settings/SettingsStore"; +import {Mjolnir} from "../../../mjolnir/Mjolnir"; module.exports = createReactClass({ displayName: 'MessageEvent', @@ -49,6 +51,10 @@ module.exports = createReactClass({ return this.refs.body && this.refs.body.getEventTileOps ? this.refs.body.getEventTileOps() : null; }, + onTileUpdate: function() { + this.forceUpdate(); + }, + render: function() { const UnknownBody = sdk.getComponent('messages.UnknownBody'); @@ -81,6 +87,20 @@ module.exports = createReactClass({ } } + if (SettingsStore.isFeatureEnabled("feature_mjolnir")) { + const allowRender = localStorage.getItem(`mx_mjolnir_render_${this.props.mxEvent.getRoomId()}__${this.props.mxEvent.getId()}`) === "true"; + + if (!allowRender) { + const userDomain = this.props.mxEvent.getSender().split(':').slice(1).join(':'); + const userBanned = Mjolnir.sharedInstance().isUserBanned(this.props.mxEvent.getSender()); + const serverBanned = Mjolnir.sharedInstance().isServerBanned(userDomain); + + if (userBanned || serverBanned) { + BodyType = sdk.getComponent('messages.MjolnirBody'); + } + } + } + return ; + onHeightChanged={this.props.onHeightChanged} + onTileUpdate={this.onTileUpdate} + />; }, }); diff --git a/src/components/views/messages/MjolnirBody.js b/src/components/views/messages/MjolnirBody.js new file mode 100644 index 0000000000..994642863b --- /dev/null +++ b/src/components/views/messages/MjolnirBody.js @@ -0,0 +1,47 @@ +/* +Copyright 2019 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import React from 'react'; +import PropTypes from 'prop-types'; +import {_t} from '../../../languageHandler'; + +export default class MjolnirBody extends React.Component { + static propTypes = { + mxEvent: PropTypes.object.isRequired, + onTileUpdate: PropTypes.func.isRequired, + }; + + constructor() { + super(); + } + + _onAllowClick = (e) => { + e.preventDefault(); + e.stopPropagation(); + + localStorage.setItem(`mx_mjolnir_render_${this.props.mxEvent.getRoomId()}__${this.props.mxEvent.getId()}`, "true"); + this.props.onTileUpdate(); + }; + + render() { + return ( +
{_t( + "You have ignored this user, so their message is hidden. Show anyways.", + {}, {a: (sub) => {sub}}, + )}
+ ); + } +} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 58fa564250..74433a9c04 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1094,6 +1094,7 @@ "Invalid file%(extra)s": "Invalid file%(extra)s", "Error decrypting image": "Error decrypting image", "Show image": "Show image", + "You have ignored this user, so their message is hidden. Show anyways.": "You have ignored this user, so their message is hidden. Show anyways.", "Error decrypting video": "Error decrypting video", "Show all": "Show all", "reacted with %(shortName)s": "reacted with %(shortName)s",