diff --git a/app/lib/server/methods/filterBadWords.js b/app/lib/server/methods/filterBadWords.js index e7bb446428268..0e09a31d17771 100644 --- a/app/lib/server/methods/filterBadWords.js +++ b/app/lib/server/methods/filterBadWords.js @@ -6,6 +6,7 @@ import { callbacks } from '../../../callbacks'; callbacks.add('beforeSaveMessage', function(message) { if (settings.get('Message_AllowBadWordsFilter')) { const badWordsList = settings.get('Message_BadWordsFilterList'); + let whiteList = settings.get('Message_BadWordsWhitelist'); let options; // Add words to the blacklist @@ -15,6 +16,12 @@ callbacks.add('beforeSaveMessage', function(message) { }; } const filter = new Filter(options); + + if (whiteList?.length) { + whiteList = whiteList.split(',').map((word) => word.trim()); + filter.removeWords(...whiteList); + } + message.msg = filter.clean(message.msg); } diff --git a/app/lib/server/startup/settings.js b/app/lib/server/startup/settings.js index f9cdeccf05770..37d02d6d91593 100644 --- a/app/lib/server/startup/settings.js +++ b/app/lib/server/startup/settings.js @@ -1046,6 +1046,10 @@ settings.addGroup('Message', function() { type: 'string', public: true, }); + this.add('Message_BadWordsWhitelist', '', { + type: 'string', + public: true, + }); this.add('Message_KeepHistory', false, { type: 'boolean', public: true, diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 96ba98256e5ec..a227de788ef9a 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -2467,6 +2467,8 @@ "Message_AudioRecorderEnabled_Description": "Requires 'audio/mp3' files to be an accepted media type within 'File Upload' settings.", "Message_BadWordsFilterList": "Add Bad Words to the Blacklist", "Message_BadWordsFilterListDescription": "Add List of Comma-separated list of bad words to filter", + "Message_BadWordsWhitelist": "Remove words from the Blacklist", + "Message_BadWordsWhitelistDescription": "Add a comma-separated list of words to be removed from filter", "Message_Characther_Limit": "Message Characther Limit", "MessageBox_view_mode": "MessageBox View Mode", "message_counter": "__counter__ message",