From 740b3e80d8391060cda461e76436bf63b90f8f66 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Tue, 31 Jan 2023 08:02:57 -0300 Subject: [PATCH 01/20] removed deprecated settings from message parser --- apps/meteor/app/api/server/lib/messages.ts | 8 -- apps/meteor/app/autolinker/server/index.js | 1 - apps/meteor/app/autolinker/server/settings.ts | 78 -------------- .../app/autotranslate/server/autotranslate.ts | 2 +- apps/meteor/app/issuelinks/server/index.js | 1 - apps/meteor/app/issuelinks/server/settings.ts | 21 ---- .../server/functions/loadMessageHistory.ts | 7 -- .../lib/server/methods/getChannelHistory.ts | 5 - .../meteor/app/lib/server/startup/settings.ts | 34 ------ apps/meteor/app/markdown/lib/markdown.js | 33 +----- apps/meteor/app/markdown/server/index.js | 12 --- apps/meteor/app/markdown/server/settings.ts | 101 ------------------ .../app/message-snippet/client/index.js | 1 - .../message-snippet/client/snippetMessage.js | 8 -- .../message-snippet/client/tabBar/tabBar.ts | 22 ---- .../app/message-snippet/server/index.js | 1 - .../server/startup/settings.ts | 8 -- apps/meteor/app/ui-message/client/message.js | 9 -- .../client/messageBox/messageBoxFormatting.ts | 14 +-- .../app/ui-utils/client/lib/messageContext.ts | 8 -- .../meteor/client/components/MarkdownText.tsx | 3 +- .../startup/renderMessage/autolinker.ts | 25 +---- .../client/startup/renderMessage/issuelink.ts | 18 +--- .../client/startup/renderMessage/markdown.ts | 12 --- .../startup/renderNotification/markdown.ts | 3 +- .../components/body/useRoomMessageContext.ts | 6 -- .../rocketchat-i18n/i18n/en.i18n.json | 27 ----- apps/meteor/server/importPackages.ts | 2 - .../server/methods/loadMissedMessages.js | 7 -- .../meteor/server/methods/loadNextMessages.js | 7 -- .../server/methods/loadSurroundingMessages.js | 7 -- apps/meteor/server/methods/messageSearch.js | 6 -- .../meteor/server/startup/migrations/index.ts | 1 + apps/meteor/server/startup/migrations/v283.ts | 40 +++++++ apps/meteor/tests/end-to-end/api/05-chat.js | 64 ----------- 35 files changed, 57 insertions(+), 545 deletions(-) delete mode 100644 apps/meteor/app/autolinker/server/index.js delete mode 100644 apps/meteor/app/autolinker/server/settings.ts delete mode 100644 apps/meteor/app/issuelinks/server/index.js delete mode 100644 apps/meteor/app/issuelinks/server/settings.ts delete mode 100644 apps/meteor/app/markdown/server/settings.ts delete mode 100644 apps/meteor/app/message-snippet/client/tabBar/tabBar.ts delete mode 100644 apps/meteor/app/message-snippet/server/startup/settings.ts create mode 100644 apps/meteor/server/startup/migrations/v283.ts diff --git a/apps/meteor/app/api/server/lib/messages.ts b/apps/meteor/app/api/server/lib/messages.ts index d6955ce7b933..2e9a3f549112 100644 --- a/apps/meteor/app/api/server/lib/messages.ts +++ b/apps/meteor/app/api/server/lib/messages.ts @@ -3,7 +3,6 @@ import type { IMessage, IUser } from '@rocket.chat/core-typings'; import { Rooms, Messages, Users } from '@rocket.chat/models'; import { canAccessRoomAsync } from '../../../authorization/server/functions/canAccessRoom'; -import { getValue } from '../../../settings/server/raw'; export async function findMentionedMessages({ uid, @@ -84,10 +83,6 @@ export async function findStarredMessages({ } export async function findSnippetedMessageById({ uid, messageId }: { uid: string; messageId: string }): Promise { - if (!(await getValue('Message_AllowSnippeting'))) { - throw new Error('error-not-allowed'); - } - if (!uid) { throw new Error('invalid-user'); } @@ -125,9 +120,6 @@ export async function findSnippetedMessages({ offset: number; total: number; }> { - if (!(await getValue('Message_AllowSnippeting'))) { - throw new Error('error-not-allowed'); - } const room = await Rooms.findOneById(roomId); if (!room || !(await canAccessRoomAsync(room, { _id: uid }))) { diff --git a/apps/meteor/app/autolinker/server/index.js b/apps/meteor/app/autolinker/server/index.js deleted file mode 100644 index 97097791afdc..000000000000 --- a/apps/meteor/app/autolinker/server/index.js +++ /dev/null @@ -1 +0,0 @@ -import './settings'; diff --git a/apps/meteor/app/autolinker/server/settings.ts b/apps/meteor/app/autolinker/server/settings.ts deleted file mode 100644 index 898e5b59a476..000000000000 --- a/apps/meteor/app/autolinker/server/settings.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -import { settingsRegistry } from '../../settings/server'; - -Meteor.startup(function () { - const enableQuery = { - _id: 'AutoLinker', - value: true, - }; - - settingsRegistry.add('AutoLinker', true, { - type: 'boolean', - group: 'Message', - section: 'AutoLinker', - public: true, - i18nLabel: 'Enabled', - alert: 'This_is_a_deprecated_feature_alert', - }); - - settingsRegistry.add('AutoLinker_StripPrefix', false, { - type: 'boolean', - group: 'Message', - section: 'AutoLinker', - public: true, - i18nDescription: 'AutoLinker_StripPrefix_Description', - enableQuery, - alert: 'This_is_a_deprecated_feature_alert', - }); - settingsRegistry.add('AutoLinker_Urls_Scheme', true, { - type: 'boolean', - group: 'Message', - section: 'AutoLinker', - public: true, - enableQuery, - alert: 'This_is_a_deprecated_feature_alert', - }); - settingsRegistry.add('AutoLinker_Urls_www', true, { - type: 'boolean', - group: 'Message', - section: 'AutoLinker', - public: true, - enableQuery, - alert: 'This_is_a_deprecated_feature_alert', - }); - settingsRegistry.add('AutoLinker_Urls_TLD', true, { - type: 'boolean', - group: 'Message', - section: 'AutoLinker', - public: true, - enableQuery, - alert: 'This_is_a_deprecated_feature_alert', - }); - settingsRegistry.add('AutoLinker_UrlsRegExp', '(://|www\\.).+', { - type: 'string', - group: 'Message', - section: 'AutoLinker', - public: true, - enableQuery, - alert: 'This_is_a_deprecated_feature_alert', - }); - settingsRegistry.add('AutoLinker_Email', true, { - type: 'boolean', - group: 'Message', - section: 'AutoLinker', - public: true, - enableQuery, - alert: 'This_is_a_deprecated_feature_alert', - }); - settingsRegistry.add('AutoLinker_Phone', true, { - type: 'boolean', - group: 'Message', - section: 'AutoLinker', - public: true, - i18nDescription: 'AutoLinker_Phone_Description', - enableQuery, - alert: 'This_is_a_deprecated_feature_alert', - }); -}); diff --git a/apps/meteor/app/autotranslate/server/autotranslate.ts b/apps/meteor/app/autotranslate/server/autotranslate.ts index 1d926fe5bb77..9ade9beaa0ef 100644 --- a/apps/meteor/app/autotranslate/server/autotranslate.ts +++ b/apps/meteor/app/autotranslate/server/autotranslate.ts @@ -165,7 +165,7 @@ export abstract class AutoTranslate { tokenizeURLs(message: IMessage): IMessage { let count = message.tokens?.length || 0; - const schemes = settings.get('Markdown_SupportSchemesForLink')?.split(',').join('|'); + const schemes = 'http,https'; // Support ![alt text](http://image url) and [text](http://link) message.msg = message.msg.replace( diff --git a/apps/meteor/app/issuelinks/server/index.js b/apps/meteor/app/issuelinks/server/index.js deleted file mode 100644 index 97097791afdc..000000000000 --- a/apps/meteor/app/issuelinks/server/index.js +++ /dev/null @@ -1 +0,0 @@ -import './settings'; diff --git a/apps/meteor/app/issuelinks/server/settings.ts b/apps/meteor/app/issuelinks/server/settings.ts deleted file mode 100644 index 57d07cf6fa54..000000000000 --- a/apps/meteor/app/issuelinks/server/settings.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { settingsRegistry } from '../../settings/server'; - -settingsRegistry.add('IssueLinks_Enabled', false, { - type: 'boolean', - i18nLabel: 'Enabled', - i18nDescription: 'IssueLinks_Incompatible', - group: 'Message', - section: 'Issue_Links', - public: true, - alert: 'This_is_a_deprecated_feature_alert', -}); - -settingsRegistry.add('IssueLinks_Template', '', { - type: 'string', - i18nLabel: 'IssueLinks_LinkTemplate', - i18nDescription: 'IssueLinks_LinkTemplate_Description', - group: 'Message', - section: 'Issue_Links', - public: true, - alert: 'This_is_a_deprecated_feature_alert', -}); diff --git a/apps/meteor/app/lib/server/functions/loadMessageHistory.ts b/apps/meteor/app/lib/server/functions/loadMessageHistory.ts index 3fe64be17d9e..0dd28d080a57 100644 --- a/apps/meteor/app/lib/server/functions/loadMessageHistory.ts +++ b/apps/meteor/app/lib/server/functions/loadMessageHistory.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ -import { settings } from '../../../settings/server'; import { Messages, Rooms } from '../../../models/server'; import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser'; import { getHiddenSystemMessages } from '../lib/getHiddenSystemMessages'; @@ -34,12 +33,6 @@ export function loadMessageHistory({ fields: {}, }; - if (!settings.get('Message_ShowEditedStatus')) { - options.fields = { - editedAt: 0, - }; - } - const records = end != null ? Messages.findVisibleByRoomIdBeforeTimestampNotContainingTypes(rid, end, hiddenMessageTypes, options, showThreadMessages).fetch() diff --git a/apps/meteor/app/lib/server/methods/getChannelHistory.ts b/apps/meteor/app/lib/server/methods/getChannelHistory.ts index 948508dd5a3a..19eae5aa5477 100644 --- a/apps/meteor/app/lib/server/methods/getChannelHistory.ts +++ b/apps/meteor/app/lib/server/methods/getChannelHistory.ts @@ -4,7 +4,6 @@ import _ from 'underscore'; import { canAccessRoom, hasPermission } from '../../../authorization/server'; import { Subscriptions, Messages, Rooms } from '../../../models/server'; -import { settings } from '../../../settings/server'; import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser'; import { getHiddenSystemMessages } from '../lib/getHiddenSystemMessages'; @@ -59,10 +58,6 @@ Meteor.methods({ limit: count, }; - if (!settings.get('Message_ShowEditedStatus')) { - options.fields = { editedAt: 0 }; - } - const records = _.isUndefined(oldest) ? Messages.findVisibleByRoomIdBeforeTimestampNotContainingTypes( rid, diff --git a/apps/meteor/app/lib/server/startup/settings.ts b/apps/meteor/app/lib/server/startup/settings.ts index 2a3b25cd9771..0b815c3d9238 100644 --- a/apps/meteor/app/lib/server/startup/settings.ts +++ b/apps/meteor/app/lib/server/startup/settings.ts @@ -548,13 +548,6 @@ settingsRegistry.addGroup('Accounts', function () { public: true, i18nLabel: 'Notifications_Sound_Volume', }); - - this.add('Accounts_Default_User_Preferences_useLegacyMessageTemplate', false, { - type: 'boolean', - public: true, - i18nLabel: 'Use_Legacy_Message_Template', - alert: 'This_is_a_deprecated_feature_alert', - }); }); this.section('Avatar', function () { @@ -1145,13 +1138,6 @@ settingsRegistry.addGroup('General', function () { settingsRegistry.addGroup('Message', function () { this.section('Message_Attachments', function () { - this.add('Message_Attachments_GroupAttach', false, { - type: 'boolean', - public: true, - i18nDescription: 'Message_Attachments_GroupAttachDescription', - alert: 'This_is_a_deprecated_feature_alert', - }); - this.add('Message_Attachments_Thumbnails_Enabled', true, { type: 'boolean', public: true, @@ -1226,11 +1212,6 @@ settingsRegistry.addGroup('Message', function () { this.add('Message_AlwaysSearchRegExp', false, { type: 'boolean', }); - this.add('Message_ShowEditedStatus', true, { - type: 'boolean', - public: true, - alert: 'This_is_a_deprecated_feature_alert', - }); this.add('Message_ShowDeletedStatus', false, { type: 'boolean', public: true, @@ -1263,14 +1244,6 @@ settingsRegistry.addGroup('Message', function () { type: 'boolean', public: true, }); - /** - * @deprecated - */ - this.add('Message_ShowFormattingTips', true, { - type: 'boolean', - public: true, - alert: 'This_is_a_deprecated_feature_alert', - }); this.add('Message_GroupingPeriod', 300, { type: 'int', public: true, @@ -1298,13 +1271,6 @@ settingsRegistry.addGroup('Message', function () { i18nLabel: 'clear_cache_now', }); // TODO: deprecate this setting in favor of App - this.add('API_EmbedDisabledFor', '', { - type: 'string', - public: true, - i18nDescription: 'API_EmbedDisabledFor_Description', - alert: 'This_is_a_deprecated_feature_alert', - }); - // TODO: deprecate this setting in favor of App this.add('API_EmbedIgnoredHosts', 'localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16', { type: 'string', i18nDescription: 'API_EmbedIgnoredHosts_Description', diff --git a/apps/meteor/app/markdown/lib/markdown.js b/apps/meteor/app/markdown/lib/markdown.js index 7ee511d403e4..2fd3aaa9676a 100644 --- a/apps/meteor/app/markdown/lib/markdown.js +++ b/apps/meteor/app/markdown/lib/markdown.js @@ -9,7 +9,6 @@ import { marked } from './parser/marked/marked'; import { original } from './parser/original/original'; import { filtered } from './parser/filtered/filtered'; import { code } from './parser/original/code'; -import { settings } from '../../settings'; const parsers = { original, @@ -33,29 +32,11 @@ class MarkdownClass { } parseMessageNotEscaped(message) { - const parser = settings.get('Markdown_Parser'); - - if (parser === 'disabled') { - return message; - } - const options = { - supportSchemesForLink: settings.get('Markdown_SupportSchemesForLink'), - headers: settings.get('Markdown_Headers'), rootUrl: Meteor.absoluteUrl(), - marked: { - gfm: settings.get('Markdown_Marked_GFM'), - tables: settings.get('Markdown_Marked_Tables'), - breaks: settings.get('Markdown_Marked_Breaks'), - pedantic: settings.get('Markdown_Marked_Pedantic'), - smartLists: settings.get('Markdown_Marked_SmartLists'), - smartypants: settings.get('Markdown_Marked_Smartypants'), - }, }; - const parse = typeof parsers[parser] === 'function' ? parsers[parser] : parsers.original; - - return parse(message, options); + return parsers.original(message, options); } mountTokensBackRecursively(message, tokenList, useHtml = true) { @@ -92,7 +73,7 @@ class MarkdownClass { filterMarkdownFromMessage(message) { return parsers.filtered(message, { - supportSchemesForLink: settings.get('Markdown_SupportSchemesForLink'), + supportSchemesForLink: 'http,https', }); } } @@ -101,19 +82,13 @@ export const Markdown = new MarkdownClass(); export const filterMarkdown = (message) => Markdown.filterMarkdownFromMessage(message); -export const createMarkdownMessageRenderer = ({ parser, ...options }) => { - if (!parser || parser === 'disabled') { - return (message) => message; - } - - const parse = typeof parsers[parser] === 'function' ? parsers[parser] : parsers.original; - +export const createMarkdownMessageRenderer = ({ ...options }) => { return (message) => { if (!message?.html?.trim()) { return message; } - return parse(message, options); + return parsers.original(message, options); }; }; diff --git a/apps/meteor/app/markdown/server/index.js b/apps/meteor/app/markdown/server/index.js index 9b4f3084c58b..1c5136d376c9 100644 --- a/apps/meteor/app/markdown/server/index.js +++ b/apps/meteor/app/markdown/server/index.js @@ -4,25 +4,13 @@ import { Tracker } from 'meteor/tracker'; import { callbacks } from '../../../lib/callbacks'; import { settings } from '../../settings/server'; import { createMarkdownMessageRenderer, createMarkdownNotificationRenderer } from '../lib/markdown'; -import './settings'; export { Markdown } from '../lib/markdown'; Meteor.startup(() => { Tracker.autorun(() => { const options = { - parser: settings.get('Markdown_Parser'), - supportSchemesForLink: settings.get('Markdown_SupportSchemesForLink'), - headers: settings.get('Markdown_Headers'), rootUrl: Meteor.absoluteUrl(), - marked: { - gfm: settings.get('Markdown_Marked_GFM'), - tables: settings.get('Markdown_Marked_Tables'), - breaks: settings.get('Markdown_Marked_Breaks'), - pedantic: settings.get('Markdown_Marked_Pedantic'), - smartLists: settings.get('Markdown_Marked_SmartLists'), - smartypants: settings.get('Markdown_Marked_Smartypants'), - }, }; const renderMessage = createMarkdownMessageRenderer(options); diff --git a/apps/meteor/app/markdown/server/settings.ts b/apps/meteor/app/markdown/server/settings.ts deleted file mode 100644 index 34e878186714..000000000000 --- a/apps/meteor/app/markdown/server/settings.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { settingsRegistry } from '../../settings/server'; - -settingsRegistry.add('Markdown_Parser', 'original', { - type: 'select', - values: [ - { - key: 'disabled', - i18nLabel: 'Disabled', - }, - { - key: 'original', - i18nLabel: 'Original', - }, - { - key: 'marked', - i18nLabel: 'Marked', - }, - ], - group: 'Message', - section: 'Markdown', - public: true, - alert: 'This_is_a_deprecated_feature_alert', -}); - -const enableQueryOriginal = { _id: 'Markdown_Parser', value: 'original' }; -settingsRegistry.add('Markdown_Headers', false, { - type: 'boolean', - group: 'Message', - section: 'Markdown', - public: true, - enableQuery: enableQueryOriginal, - alert: 'This_is_a_deprecated_feature_alert', -}); -settingsRegistry.add('Markdown_SupportSchemesForLink', 'http,https', { - type: 'string', - group: 'Message', - section: 'Markdown', - public: true, - i18nDescription: 'Markdown_SupportSchemesForLink_Description', - enableQuery: enableQueryOriginal, - alert: 'This_is_a_deprecated_feature_alert', -}); - -const enableQueryMarked = { _id: 'Markdown_Parser', value: 'marked' }; -settingsRegistry.add('Markdown_Marked_GFM', true, { - type: 'boolean', - group: 'Message', - section: 'Markdown', - public: true, - enableQuery: enableQueryMarked, - alert: 'This_is_a_deprecated_feature_alert', -}); -settingsRegistry.add('Markdown_Marked_Tables', true, { - type: 'boolean', - group: 'Message', - section: 'Markdown', - public: true, - enableQuery: enableQueryMarked, - alert: 'This_is_a_deprecated_feature_alert', -}); -settingsRegistry.add('Markdown_Marked_Breaks', true, { - type: 'boolean', - group: 'Message', - section: 'Markdown', - public: true, - enableQuery: enableQueryMarked, - alert: 'This_is_a_deprecated_feature_alert', -}); -settingsRegistry.add('Markdown_Marked_Pedantic', false, { - type: 'boolean', - group: 'Message', - section: 'Markdown', - public: true, - alert: 'This_is_a_deprecated_feature_alert', - enableQuery: [ - { - _id: 'Markdown_Parser', - value: 'marked', - }, - { - _id: 'Markdown_Marked_GFM', - value: false, - }, - ], -}); -settingsRegistry.add('Markdown_Marked_SmartLists', true, { - type: 'boolean', - group: 'Message', - section: 'Markdown', - public: true, - enableQuery: enableQueryMarked, - alert: 'This_is_a_deprecated_feature_alert', -}); -settingsRegistry.add('Markdown_Marked_Smartypants', true, { - type: 'boolean', - group: 'Message', - section: 'Markdown', - public: true, - enableQuery: enableQueryMarked, - alert: 'This_is_a_deprecated_feature_alert', -}); diff --git a/apps/meteor/app/message-snippet/client/index.js b/apps/meteor/app/message-snippet/client/index.js index d5b477773204..e1d776684406 100644 --- a/apps/meteor/app/message-snippet/client/index.js +++ b/apps/meteor/app/message-snippet/client/index.js @@ -2,7 +2,6 @@ import './messageType'; import './snippetMessage'; import './page/snippetPage.html'; import './page/snippetPage'; -import './tabBar/tabBar'; import './tabBar/views/snippetedMessages.html'; import './tabBar/views/snippetedMessages'; import './page/stylesheets/snippetPage.css'; diff --git a/apps/meteor/app/message-snippet/client/snippetMessage.js b/apps/meteor/app/message-snippet/client/snippetMessage.js index 3c8a35d6cfdc..3641086975ad 100644 --- a/apps/meteor/app/message-snippet/client/snippetMessage.js +++ b/apps/meteor/app/message-snippet/client/snippetMessage.js @@ -1,6 +1,5 @@ import { Meteor } from 'meteor/meteor'; -import { settings } from '../../settings'; import { ChatMessage, Subscriptions } from '../../models/client'; Meteor.methods({ @@ -8,13 +7,6 @@ Meteor.methods({ if (typeof Meteor.userId() === 'undefined' || Meteor.userId() === null) { return false; } - if ( - typeof settings.get('Message_AllowSnippeting') === 'undefined' || - settings.get('Message_AllowSnippeting') === null || - settings.get('Message_AllowSnippeting') === false - ) { - return false; - } const subscription = Subscriptions.findOne({ 'rid': message.rid, 'u._id': Meteor.userId() }); diff --git a/apps/meteor/app/message-snippet/client/tabBar/tabBar.ts b/apps/meteor/app/message-snippet/client/tabBar/tabBar.ts deleted file mode 100644 index 6e36a47833a8..000000000000 --- a/apps/meteor/app/message-snippet/client/tabBar/tabBar.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { useMemo } from 'react'; -import { useSetting } from '@rocket.chat/ui-contexts'; - -import { addAction } from '../../../../client/views/room/lib/Toolbox'; - -addAction('snippeted-messages', () => { - const snippetingEnabled = useSetting('Message_AllowSnippeting'); - return useMemo( - () => - snippetingEnabled - ? { - groups: ['channel', 'group', 'direct', 'direct_multiple', 'team'], - id: 'snippeted-messages', - title: 'snippet-message', - icon: 'code', - template: 'snippetedMessages', - order: 20, - } - : null, - [snippetingEnabled], - ); -}); diff --git a/apps/meteor/app/message-snippet/server/index.js b/apps/meteor/app/message-snippet/server/index.js index 74e7fa9524c2..7ed8e7bdc691 100644 --- a/apps/meteor/app/message-snippet/server/index.js +++ b/apps/meteor/app/message-snippet/server/index.js @@ -1,3 +1,2 @@ -import './startup/settings'; import './methods/snippetMessage'; import './requests'; diff --git a/apps/meteor/app/message-snippet/server/startup/settings.ts b/apps/meteor/app/message-snippet/server/startup/settings.ts deleted file mode 100644 index eb20c713cb5c..000000000000 --- a/apps/meteor/app/message-snippet/server/startup/settings.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { settingsRegistry } from '../../../settings/server'; - -settingsRegistry.add('Message_AllowSnippeting', false, { - type: 'boolean', - public: true, - group: 'Message', - alert: 'This_is_a_deprecated_feature_alert', -}); diff --git a/apps/meteor/app/ui-message/client/message.js b/apps/meteor/app/ui-message/client/message.js index f0bffebb9a52..43fe4765de81 100644 --- a/apps/meteor/app/ui-message/client/message.js +++ b/apps/meteor/app/ui-message/client/message.js @@ -309,15 +309,6 @@ Template.message.helpers({ return false; } - // check if oembed is disabled for message's sender - if ( - (settings.API_EmbedDisabledFor || '') - .split(',') - .map((username) => username.trim()) - .includes(msg.u && msg.u.username) - ) { - return false; - } return true; }, reactions() { diff --git a/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts b/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts index 4b58a34897b1..917f66a1a2d8 100644 --- a/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts +++ b/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts @@ -27,45 +27,45 @@ export const formattingButtons: ReadonlyArray = [ icon: 'bold', pattern: '*{{text}}*', command: 'b', - condition: () => Markdown && settings.get('Markdown_Parser') === 'original', + condition: () => !!Markdown, }, { label: 'bold', icon: 'bold', pattern: '**{{text}}**', command: 'b', - condition: () => Markdown && settings.get('Markdown_Parser') === 'marked', + condition: () => !!Markdown, }, { label: 'italic', icon: 'italic', pattern: '_{{text}}_', command: 'i', - condition: () => Markdown && settings.get('Markdown_Parser') !== 'disabled', + condition: () => !!Markdown, }, { label: 'strike', icon: 'strike', pattern: '~{{text}}~', - condition: () => Markdown && settings.get('Markdown_Parser') === 'original', + condition: () => !!Markdown, }, { label: 'strike', icon: 'strike', pattern: '~~{{text}}~~', - condition: () => Markdown && settings.get('Markdown_Parser') === 'marked', + condition: () => !!Markdown, }, { label: 'inline_code', icon: 'code', pattern: '`{{text}}`', - condition: () => Markdown && settings.get('Markdown_Parser') !== 'disabled', + condition: () => !!Markdown, }, { label: 'multi_line', icon: 'multiline', pattern: '```\n{{text}}\n``` ', - condition: () => Markdown && settings.get('Markdown_Parser') !== 'disabled', + condition: () => !!Markdown, }, { label: 'KaTeX' as TranslationKey, diff --git a/apps/meteor/app/ui-utils/client/lib/messageContext.ts b/apps/meteor/app/ui-utils/client/lib/messageContext.ts index 3312be309c15..f8c64cb65681 100644 --- a/apps/meteor/app/ui-utils/client/lib/messageContext.ts +++ b/apps/meteor/app/ui-utils/client/lib/messageContext.ts @@ -70,12 +70,8 @@ export const createMessageContext = ({ // eslint-disable-next-line @typescript-eslint/naming-convention Message_AllowEditing_BlockEditInMinutes = settings.get('Message_AllowEditing_BlockEditInMinutes'), // eslint-disable-next-line @typescript-eslint/naming-convention - Message_ShowEditedStatus = settings.get('Message_ShowEditedStatus'), - // eslint-disable-next-line @typescript-eslint/naming-convention API_Embed = settings.get('API_Embed'), // eslint-disable-next-line @typescript-eslint/naming-convention - API_EmbedDisabledFor = settings.get('API_EmbedDisabledFor'), - // eslint-disable-next-line @typescript-eslint/naming-convention Message_GroupingPeriod = settings.get('Message_GroupingPeriod') * 1000, }: { uid?: IUser['_id'] | null; @@ -100,9 +96,7 @@ export const createMessageContext = ({ AutoTranslate_Enabled?: unknown; Message_AllowEditing?: unknown; Message_AllowEditing_BlockEditInMinutes?: unknown; - Message_ShowEditedStatus?: unknown; API_Embed?: unknown; - API_EmbedDisabledFor?: unknown; Message_GroupingPeriod?: unknown; }) => { return { @@ -125,9 +119,7 @@ export const createMessageContext = ({ AutoTranslate_Enabled, Message_AllowEditing, Message_AllowEditing_BlockEditInMinutes, - Message_ShowEditedStatus, API_Embed, - API_EmbedDisabledFor, Message_GroupingPeriod, }, } as const; diff --git a/apps/meteor/client/components/MarkdownText.tsx b/apps/meteor/client/components/MarkdownText.tsx index a5591227aad9..23f2968e8582 100644 --- a/apps/meteor/client/components/MarkdownText.tsx +++ b/apps/meteor/client/components/MarkdownText.tsx @@ -1,5 +1,4 @@ import { Box } from '@rocket.chat/fuselage'; -import { useSetting } from '@rocket.chat/ui-contexts'; import dompurify from 'dompurify'; import { marked } from 'marked'; import type { ComponentProps, FC } from 'react'; @@ -89,7 +88,7 @@ const MarkdownText: FC> = ({ let markedOptions: marked.MarkedOptions; - const schemes = useSetting('Markdown_SupportSchemesForLink') as string; + const schemes = 'http,https'; switch (variant) { case 'inline': diff --git a/apps/meteor/client/startup/renderMessage/autolinker.ts b/apps/meteor/client/startup/renderMessage/autolinker.ts index 2429b0a1a9e7..7eecf0b61c9b 100644 --- a/apps/meteor/client/startup/renderMessage/autolinker.ts +++ b/apps/meteor/client/startup/renderMessage/autolinker.ts @@ -1,33 +1,10 @@ import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; -import { settings } from '../../../app/settings/client'; import { callbacks } from '../../../lib/callbacks'; Meteor.startup(() => { Tracker.autorun(() => { - const isEnabled = settings.get('AutoLinker') === true; - - if (!isEnabled) { - callbacks.remove('renderMessage', 'autolinker'); - return; - } - - const options = { - stripPrefix: settings.get('AutoLinker_StripPrefix'), - urls: { - schemeMatches: settings.get('AutoLinker_Urls_Scheme'), - wwwMatches: settings.get('AutoLinker_Urls_www'), - tldMatches: settings.get('AutoLinker_Urls_TLD'), - }, - email: settings.get('AutoLinker_Email'), - phone: settings.get('AutoLinker_Phone'), - }; - - import('../../../app/autolinker/client').then(({ createAutolinkerMessageRenderer }) => { - const renderMessage = createAutolinkerMessageRenderer(options); - callbacks.remove('renderMessage', 'autolinker'); - callbacks.add('renderMessage', renderMessage, callbacks.priority.MEDIUM, 'autolinker'); - }); + callbacks.remove('renderMessage', 'autolinker'); }); }); diff --git a/apps/meteor/client/startup/renderMessage/issuelink.ts b/apps/meteor/client/startup/renderMessage/issuelink.ts index ba96e8253397..6e238f2d3cc1 100644 --- a/apps/meteor/client/startup/renderMessage/issuelink.ts +++ b/apps/meteor/client/startup/renderMessage/issuelink.ts @@ -1,26 +1,10 @@ import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; -import { settings } from '../../../app/settings/client'; import { callbacks } from '../../../lib/callbacks'; Meteor.startup(() => { Tracker.autorun(() => { - const isEnabled = settings.get('IssueLinks_Enabled'); - - if (!isEnabled) { - callbacks.remove('renderMessage', 'issuelink'); - return; - } - - const options = { - template: settings.get('IssueLinks_Template'), - }; - - import('../../../app/issuelinks/client').then(({ createIssueLinksMessageRenderer }) => { - const renderMessage = createIssueLinksMessageRenderer(options); - callbacks.remove('renderMessage', 'issuelink'); - callbacks.add('renderMessage', renderMessage, callbacks.priority.MEDIUM, 'issuelink'); - }); + callbacks.remove('renderMessage', 'issuelink'); }); }); diff --git a/apps/meteor/client/startup/renderMessage/markdown.ts b/apps/meteor/client/startup/renderMessage/markdown.ts index d13e4f3b9cda..a741b105c42e 100644 --- a/apps/meteor/client/startup/renderMessage/markdown.ts +++ b/apps/meteor/client/startup/renderMessage/markdown.ts @@ -1,24 +1,12 @@ import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; -import { settings } from '../../../app/settings/client'; import { callbacks } from '../../../lib/callbacks'; Meteor.startup(() => { Tracker.autorun(() => { const options = { - parser: settings.get('Markdown_Parser'), - supportSchemesForLink: settings.get('Markdown_SupportSchemesForLink'), - headers: settings.get('Markdown_Headers'), rootUrl: Meteor.absoluteUrl(), - marked: { - gfm: settings.get('Markdown_Marked_GFM'), - tables: settings.get('Markdown_Marked_Tables'), - breaks: settings.get('Markdown_Marked_Breaks'), - pedantic: settings.get('Markdown_Marked_Pedantic'), - smartLists: settings.get('Markdown_Marked_SmartLists'), - smartypants: settings.get('Markdown_Marked_Smartypants'), - }, }; import('../../../app/markdown/client').then(({ createMarkdownMessageRenderer }) => { diff --git a/apps/meteor/client/startup/renderNotification/markdown.ts b/apps/meteor/client/startup/renderNotification/markdown.ts index 8c83f75776d0..ab451b47e070 100644 --- a/apps/meteor/client/startup/renderNotification/markdown.ts +++ b/apps/meteor/client/startup/renderNotification/markdown.ts @@ -1,11 +1,10 @@ import { Meteor } from 'meteor/meteor'; -import { settings } from '../../../app/settings/client'; import { callbacks } from '../../../lib/callbacks'; Meteor.startup(() => { const options = { - supportSchemesForLink: settings.get('Markdown_SupportSchemesForLink'), + supportSchemesForLink: 'http,https', }; import('../../../app/markdown/client').then(({ createMarkdownNotificationRenderer }) => { diff --git a/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts b/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts index a5f01705adf4..3b1ab5c91f3d 100644 --- a/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts +++ b/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts @@ -28,9 +28,7 @@ export const useRoomMessageContext = (room: IRoom) => { const autoTranslateEnabled = useSetting('AutoTranslate_Enabled'); const allowEditing = useSetting('Message_AllowEditing'); const blockEditInMinutes = useSetting('Message_AllowEditing_BlockEditInMinutes'); - const showEditedStatus = useSetting('Message_ShowEditedStatus'); const embed = useSetting('API_Embed'); - const embedDisabledFor = useSetting('API_EmbedDisabledFor'); const groupingPeriod = useSetting('Message_GroupingPeriod') as number; return useMemo( @@ -56,9 +54,7 @@ export const useRoomMessageContext = (room: IRoom) => { AutoTranslate_Enabled: autoTranslateEnabled, Message_AllowEditing: allowEditing, Message_AllowEditing_BlockEditInMinutes: blockEditInMinutes, - Message_ShowEditedStatus: showEditedStatus, API_Embed: embed, - API_EmbedDisabledFor: embedDisabledFor, Message_GroupingPeriod: groupingPeriod * 1000, }), [ @@ -70,7 +66,6 @@ export const useRoomMessageContext = (room: IRoom) => { collapseMediaByDefault, displayRoles, embed, - embedDisabledFor, groupingPeriod, hasPermissionDeleteMessage, hasPermissionDeleteOwnMessage, @@ -79,7 +74,6 @@ export const useRoomMessageContext = (room: IRoom) => { rid, room, saveMobileBandwidth, - showEditedStatus, subscription, translateLanguage, uid, diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index 2335e52663a6..c32293d75f71 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -399,8 +399,6 @@ "API_Embed_Description": "Whether embedded link previews are enabled or not when a user posts a link to a website.", "API_Embed_UserAgent": "Embed Request User Agent", "API_EmbedCacheExpirationDays": "Embed Cache Expiration Days", - "API_EmbedDisabledFor": "Disable Embed for Users", - "API_EmbedDisabledFor_Description": "Comma-separated list of usernames to disable the embedded link previews.", "API_EmbedIgnoredHosts": "Embed Ignored Hosts", "API_EmbedIgnoredHosts_Description": "Comma-separated list of hosts or CIDR addresses, eg. localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16", "API_EmbedSafePorts": "Safe Ports", @@ -644,16 +642,6 @@ "Auto_Translate": "Auto-Translate", "auto-translate": "Auto Translate", "auto-translate_description": "Permission to use the auto translate tool", - "AutoLinker": "AutoLinker", - "AutoLinker_Email": "AutoLinker Email", - "AutoLinker_Phone": "AutoLinker Phone", - "AutoLinker_Phone_Description": "Automatically linked for Phone numbers. e.g. `(123)456-7890`", - "AutoLinker_StripPrefix": "AutoLinker Strip Prefix", - "AutoLinker_StripPrefix_Description": "Short display. e.g. https://rocket.chat => rocket.chat", - "AutoLinker_Urls_Scheme": "AutoLinker Scheme:// URLs", - "AutoLinker_Urls_TLD": "AutoLinker TLD URLs", - "AutoLinker_Urls_www": "AutoLinker 'www' URLs", - "AutoLinker_UrlsRegExp": "AutoLinker URL Regular Expression", "Automatic_Translation": "Automatic Translation", "AutoTranslate": "Auto-Translate", "AutoTranslate_APIKey": "API Key", @@ -3137,16 +3125,6 @@ "Mark_as_unread": "Mark As Unread", "Mark_read": "Mark Read", "Mark_unread": "Mark Unread", - "Markdown_Headers": "Allow Markdown headers in messages", - "Markdown_Marked_Breaks": "Enable Marked Breaks", - "Markdown_Marked_GFM": "Enable Marked GFM", - "Markdown_Marked_Pedantic": "Enable Marked Pedantic", - "Markdown_Marked_SmartLists": "Enable Marked Smart Lists", - "Markdown_Marked_Smartypants": "Enable Marked Smartypants", - "Markdown_Marked_Tables": "Enable Marked Tables", - "Markdown_Parser": "Markdown Parser", - "Markdown_SupportSchemesForLink": "Markdown Support Schemes for Link", - "Markdown_SupportSchemesForLink_Description": "Comma-separated list of allowed schemes", "Marketplace": "Marketplace", "Marketplace_app_last_updated": "Last updated __lastUpdated__", "Marketplace_view_marketplace": "View Marketplace", @@ -3200,15 +3178,12 @@ "Message_AllowEditing_BlockEditInMinutesDescription": "Enter 0 to disable blocking.", "Message_AllowPinning": "Allow Message Pinning", "Message_AllowPinning_Description": "Allow messages to be pinned to any of the channels.", - "Message_AllowSnippeting": "Allow Message Snippeting", "Message_AllowStarring": "Allow Message Starring", "Message_AllowUnrecognizedSlashCommand": "Allow Unrecognized Slash Commands", "Message_Already_Sent": "This message has already been sent and is being processed by the server", "Message_AlwaysSearchRegExp": "Always Search Using RegExp", "Message_AlwaysSearchRegExp_Description": "We recommend to set `True` if your language is not supported on MongoDB text search.", "Message_Attachments": "Message Attachments", - "Message_Attachments_GroupAttach": "Group Attachment Buttons", - "Message_Attachments_GroupAttachDescription": "This groups the icons under an expandable menu. Takes up less screen space.", "Message_Attachments_Thumbnails_Enabled": "Enable image thumbnails to save bandwith", "Message_Attachments_Thumbnails_Width": "Thumbnail's max width (in pixels)", "Message_Attachments_Thumbnails_Height": "Thumbnail's max height (in pixels)", @@ -3302,8 +3277,6 @@ "Message_is_removed": "message removed", "Message_sent_by_email": "Message sent by Email", "Message_ShowDeletedStatus": "Show Deleted Status", - "Message_ShowEditedStatus": "Show Edited Status", - "Message_ShowFormattingTips": "Show Formatting Tips", "Message_Formatting_Toolbox": "Formatting Toolbox", "Message_composer_toolbox_primary_actions": "Composer Primary Actions", "Message_composer_toolbox_secondary_actions": "Composer Secondary Actions", diff --git a/apps/meteor/server/importPackages.ts b/apps/meteor/server/importPackages.ts index ea3a350d342f..a15dfce24d11 100644 --- a/apps/meteor/server/importPackages.ts +++ b/apps/meteor/server/importPackages.ts @@ -6,7 +6,6 @@ import '../app/api/server'; import '../app/apple/server'; import '../app/assets/server'; import '../app/authorization'; -import '../app/autolinker/server'; import '../app/autotranslate/server'; import '../app/bot-helpers/server'; import '../app/cas/server'; @@ -39,7 +38,6 @@ import '../app/importer-slack/server'; import '../app/importer-slack-users/server'; import '../app/integrations/server'; import '../app/irc'; -import '../app/issuelinks/server'; import '../app/katex/server'; import '../app/lib/server'; import '../app/livestream/server'; diff --git a/apps/meteor/server/methods/loadMissedMessages.js b/apps/meteor/server/methods/loadMissedMessages.js index 0b00ff8d6c83..e9c829976fbb 100644 --- a/apps/meteor/server/methods/loadMissedMessages.js +++ b/apps/meteor/server/methods/loadMissedMessages.js @@ -3,7 +3,6 @@ import { check } from 'meteor/check'; import { canAccessRoomId } from '../../app/authorization/server'; import { Messages } from '../../app/models/server'; -import { settings } from '../../app/settings/server'; Meteor.methods({ loadMissedMessages(rid, start) { @@ -26,12 +25,6 @@ Meteor.methods({ }, }; - if (!settings.get('Message_ShowEditedStatus')) { - options.fields = { - editedAt: 0, - }; - } - return Messages.findVisibleByRoomIdAfterTimestamp(rid, start, options).fetch(); }, }); diff --git a/apps/meteor/server/methods/loadNextMessages.js b/apps/meteor/server/methods/loadNextMessages.js index affd9ef42316..d83e308f8390 100644 --- a/apps/meteor/server/methods/loadNextMessages.js +++ b/apps/meteor/server/methods/loadNextMessages.js @@ -3,7 +3,6 @@ import { check } from 'meteor/check'; import { canAccessRoomId } from '../../app/authorization/server'; import { Messages } from '../../app/models/server'; -import { settings } from '../../app/settings/server'; import { normalizeMessagesForUser } from '../../app/utils/server/lib/normalizeMessagesForUser'; Meteor.methods({ @@ -34,12 +33,6 @@ Meteor.methods({ limit, }; - if (!settings.get('Message_ShowEditedStatus')) { - options.fields = { - editedAt: 0, - }; - } - let records; if (end) { records = Messages.findVisibleByRoomIdAfterTimestamp(rid, end, options).fetch(); diff --git a/apps/meteor/server/methods/loadSurroundingMessages.js b/apps/meteor/server/methods/loadSurroundingMessages.js index 4fa92b0e79ac..f0ea978735db 100644 --- a/apps/meteor/server/methods/loadSurroundingMessages.js +++ b/apps/meteor/server/methods/loadSurroundingMessages.js @@ -3,7 +3,6 @@ import { check } from 'meteor/check'; import { canAccessRoomId } from '../../app/authorization/server'; import { Messages } from '../../app/models/server'; -import { settings } from '../../app/settings/server'; import { normalizeMessagesForUser } from '../../app/utils/server/lib/normalizeMessagesForUser'; Meteor.methods({ @@ -42,12 +41,6 @@ Meteor.methods({ limit: Math.ceil(limit / 2), }; - if (!settings.get('Message_ShowEditedStatus')) { - options.fields = { - editedAt: 0, - }; - } - const messages = Messages.findVisibleByRoomIdBeforeTimestamp(message.rid, message.ts, options).fetch(); const moreBefore = messages.length === options.limit; diff --git a/apps/meteor/server/methods/messageSearch.js b/apps/meteor/server/methods/messageSearch.js index 126b774fba62..fe5e650012a8 100644 --- a/apps/meteor/server/methods/messageSearch.js +++ b/apps/meteor/server/methods/messageSearch.js @@ -245,12 +245,6 @@ Meteor.methods({ }; } - if (!settings.get('Message_ShowEditedStatus')) { - options.projection = { - editedAt: 0, - }; - } - result.message.docs = Promise.await( Messages.find(query, { readPreference: readSecondaryPreferred(Messages.col.s.db), diff --git a/apps/meteor/server/startup/migrations/index.ts b/apps/meteor/server/startup/migrations/index.ts index 958502f81660..377fcb8e4460 100644 --- a/apps/meteor/server/startup/migrations/index.ts +++ b/apps/meteor/server/startup/migrations/index.ts @@ -41,4 +41,5 @@ import './v279'; import './v280'; import './v281'; import './v282'; +import './v283'; import './xrun'; diff --git a/apps/meteor/server/startup/migrations/v283.ts b/apps/meteor/server/startup/migrations/v283.ts new file mode 100644 index 000000000000..d3bdb6cda64b --- /dev/null +++ b/apps/meteor/server/startup/migrations/v283.ts @@ -0,0 +1,40 @@ +import { Settings } from '@rocket.chat/models'; + +import { addMigration } from '../../lib/migrations'; + +addMigration({ + version: 283, + up() { + const deprecatedSettings = [ + 'Markdown_Parser', + 'Markdown_Headers', + 'Markdown_SupportSchemesForLink', + 'Markdown_Marked_GFM', + 'Markdown_Marked_Tables', + 'Markdown_Marked_Breaks', + 'Markdown_Marked_Pedantic', + 'Markdown_Marked_SmartLists', + 'Markdown_Marked_Smartypants', + 'Message_AllowSnippeting', + 'Message_Attachments_GroupAttach', + 'Message_ShowEditedStatus', + 'Message_ShowFormattingTips', + 'Accounts_Default_User_Preferences_useLegacyMessageTemplate', + 'AutoLinker', + 'AutoLinker_StripPrefix', + 'AutoLinker_Urls_Scheme', + 'AutoLinker_Urls_www', + 'AutoLinker_Urls_TLD', + 'AutoLinker_UrlsRegExp', + 'AutoLinker_Email', + 'AutoLinker_Phone', + 'IssueLinks_Enabled', + 'IssueLinks_Template', + 'API_EmbedDisabledFor', + ]; + + Settings.deleteMany({ + _id: { $in: deprecatedSettings }, + }); + }, +}); diff --git a/apps/meteor/tests/end-to-end/api/05-chat.js b/apps/meteor/tests/end-to-end/api/05-chat.js index 80c19d03521c..f26b58bc21ed 100644 --- a/apps/meteor/tests/end-to-end/api/05-chat.js +++ b/apps/meteor/tests/end-to-end/api/05-chat.js @@ -1978,37 +1978,6 @@ describe('[Chat]', function () { }); }); - describe('[/chat.getSnippetedMessageById]', () => { - it('should return an error when the snippeted messages is disabled', (done) => { - updateSetting('Message_AllowSnippeting', false).then(() => { - request - .get(api('chat.getSnippetedMessageById?messageId=invalid-id')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(400) - .expect((res) => { - expect(res.body).to.have.property('success', false); - expect(res.body.error).to.be.equal('error-not-allowed'); - }) - .end(done); - }); - }); - it('should return an error when the required "messageId" parameter is not sent', (done) => { - updateSetting('Message_AllowSnippeting', true).then(() => { - request - .get(api('chat.getSnippetedMessageById')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(400) - .expect((res) => { - expect(res.body).to.have.property('success', false); - expect(res.body.errorType).to.be.equal('error-invalid-params'); - }) - .end(done); - }); - }); - }); - describe('[/chat.getSnippetedMessages]', () => { it('should return an error when the required "roomId" parameter is not sent', (done) => { request @@ -2036,39 +2005,6 @@ describe('[Chat]', function () { .end(done); }); - it('should return an error when the snippeted messages is disabled', (done) => { - updateSetting('Message_AllowSnippeting', false).then(() => { - request - .get(api('chat.getSnippetedMessages?roomId=invalid-room')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(400) - .expect((res) => { - expect(res.body).to.have.property('success', false); - expect(res.body.error).to.be.equal('error-not-allowed'); - }) - .end(done); - }); - }); - - it('should return the snippeted messages', (done) => { - updateSetting('Message_AllowSnippeting', true).then(() => { - request - .get(api('chat.getSnippetedMessages?roomId=GENERAL')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - expect(res.body.messages).to.be.an('array'); - expect(res.body).to.have.property('offset'); - expect(res.body).to.have.property('total'); - expect(res.body).to.have.property('count'); - }) - .end(done); - }); - }); - it('should return an error when the messageId is invalid', (done) => { request .get(api('chat.getSnippetedMessageById?messageId=invalid-id')) From a4ea2227fc72b24a31cef09deb447f0d8cba6715 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Wed, 1 Feb 2023 09:37:41 -0300 Subject: [PATCH 02/20] updates --- apps/meteor/app/markdown/lib/markdown.js | 6 ++---- apps/meteor/app/markdown/server/index.js | 5 +---- apps/meteor/client/startup/renderNotification/markdown.ts | 6 +----- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/apps/meteor/app/markdown/lib/markdown.js b/apps/meteor/app/markdown/lib/markdown.js index 2fd3aaa9676a..a3a95e295dc8 100644 --- a/apps/meteor/app/markdown/lib/markdown.js +++ b/apps/meteor/app/markdown/lib/markdown.js @@ -72,9 +72,7 @@ class MarkdownClass { } filterMarkdownFromMessage(message) { - return parsers.filtered(message, { - supportSchemesForLink: 'http,https', - }); + return parsers.filtered(message); } } @@ -92,4 +90,4 @@ export const createMarkdownMessageRenderer = ({ ...options }) => { }; }; -export const createMarkdownNotificationRenderer = (options) => (message) => parsers.filtered(message, options); +export const createMarkdownNotificationRenderer = () => (message) => parsers.filtered(message); diff --git a/apps/meteor/app/markdown/server/index.js b/apps/meteor/app/markdown/server/index.js index 1c5136d376c9..8cf4e3078e48 100644 --- a/apps/meteor/app/markdown/server/index.js +++ b/apps/meteor/app/markdown/server/index.js @@ -2,7 +2,6 @@ import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; import { callbacks } from '../../../lib/callbacks'; -import { settings } from '../../settings/server'; import { createMarkdownMessageRenderer, createMarkdownNotificationRenderer } from '../lib/markdown'; export { Markdown } from '../lib/markdown'; @@ -17,8 +16,6 @@ Meteor.startup(() => { callbacks.add('renderMessage', renderMessage, callbacks.priority.HIGH, 'markdown'); }); - const renderNotification = createMarkdownNotificationRenderer({ - supportSchemesForLink: settings.get('Markdown_SupportSchemesForLink'), - }); + const renderNotification = createMarkdownNotificationRenderer(); callbacks.add('renderNotification', renderNotification, callbacks.priority.HIGH, 'filter-markdown'); }); diff --git a/apps/meteor/client/startup/renderNotification/markdown.ts b/apps/meteor/client/startup/renderNotification/markdown.ts index ab451b47e070..1d8ca18164e8 100644 --- a/apps/meteor/client/startup/renderNotification/markdown.ts +++ b/apps/meteor/client/startup/renderNotification/markdown.ts @@ -3,12 +3,8 @@ import { Meteor } from 'meteor/meteor'; import { callbacks } from '../../../lib/callbacks'; Meteor.startup(() => { - const options = { - supportSchemesForLink: 'http,https', - }; - import('../../../app/markdown/client').then(({ createMarkdownNotificationRenderer }) => { - const renderNotification = createMarkdownNotificationRenderer(options); + const renderNotification = createMarkdownNotificationRenderer(); callbacks.remove('renderNotification', 'filter-markdown'); callbacks.add('renderNotification', renderNotification, callbacks.priority.HIGH, 'filter-markdown'); }); From 5ca47aeb9ed0479b018c56bebf0a9bcbc732c4d0 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 3 Feb 2023 15:08:57 -0300 Subject: [PATCH 03/20] removed additional settings and fixed conditions --- .../meteor/app/lib/server/startup/settings.ts | 9 -------- apps/meteor/app/oembed/server/server.ts | 23 ------------------- .../client/messageBox/messageBoxFormatting.ts | 12 ++-------- .../rocketchat-i18n/i18n/en.i18n.json | 5 ---- apps/meteor/server/startup/migrations/v283.ts | 2 ++ 5 files changed, 4 insertions(+), 47 deletions(-) diff --git a/apps/meteor/app/lib/server/startup/settings.ts b/apps/meteor/app/lib/server/startup/settings.ts index aee085752b17..20565cac4d1c 100644 --- a/apps/meteor/app/lib/server/startup/settings.ts +++ b/apps/meteor/app/lib/server/startup/settings.ts @@ -1284,15 +1284,6 @@ settingsRegistry.addGroup('Message', function () { actionText: 'clear', i18nLabel: 'clear_cache_now', }); - // TODO: deprecate this setting in favor of App - this.add('API_EmbedIgnoredHosts', 'localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16', { - type: 'string', - i18nDescription: 'API_EmbedIgnoredHosts_Description', - }); - // TODO: deprecate this setting in favor of App - this.add('API_EmbedSafePorts', '80, 443', { - type: 'string', - }); this.add('Message_TimeFormat', 'LT', { type: 'string', public: true, diff --git a/apps/meteor/app/oembed/server/server.ts b/apps/meteor/app/oembed/server/server.ts index f5071b2238b6..11d92bfb3f20 100644 --- a/apps/meteor/app/oembed/server/server.ts +++ b/apps/meteor/app/oembed/server/server.ts @@ -70,30 +70,7 @@ const getUrlContent = async function (urlObjStr: string | URL.UrlWithStringQuery urlObj = urlObjStr; } - const portsProtocol = new Map( - Object.entries({ - 80: 'http:', - 8080: 'http:', - 443: 'https:', - }), - ); - const parsedUrl = _.pick(urlObj, ['host', 'hash', 'pathname', 'protocol', 'port', 'query', 'search', 'hostname']); - const ignoredHosts = settings.get('API_EmbedIgnoredHosts').replace(/\s/g, '').split(',') || []; - if (parsedUrl.hostname && (ignoredHosts.includes(parsedUrl.hostname) || ipRangeCheck(parsedUrl.hostname, ignoredHosts))) { - throw new Error('invalid host'); - } - - const safePorts = settings.get('API_EmbedSafePorts').replace(/\s/g, '').split(',') || []; - - if (safePorts.length > 0 && parsedUrl.port && !safePorts.includes(parsedUrl.port)) { - throw new Error('invalid/unsafe port'); - } - - if (safePorts.length > 0 && !parsedUrl.port && !safePorts.some((port) => portsProtocol.get(port) === parsedUrl.protocol)) { - throw new Error('invalid/unsafe port'); - } - const data = callbacks.run('oembed:beforeGetUrlContent', { urlObj, parsedUrl, diff --git a/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts b/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts index 8a8d0811db15..353a314c2604 100644 --- a/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts +++ b/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts @@ -2,7 +2,6 @@ import type { Icon } from '@rocket.chat/fuselage'; import type { TranslationKey } from '@rocket.chat/ui-contexts'; import type { ComponentProps } from 'react'; -import { Markdown } from '../../../markdown/client'; import { settings } from '../../../settings/client'; export type FormattingButton = @@ -13,13 +12,13 @@ export type FormattingButton = // text?: () => string | undefined; command?: string; link?: string; - condition: () => boolean; + condition?: () => boolean; } | { label: TranslationKey; text: () => string | undefined; link: string; - condition: () => boolean; + condition?: () => boolean; }; export const formattingButtons: ReadonlyArray = [ @@ -28,45 +27,38 @@ export const formattingButtons: ReadonlyArray = [ icon: 'bold', pattern: '*{{text}}*', command: 'b', - condition: () => !!Markdown, }, { label: 'bold', icon: 'bold', pattern: '**{{text}}**', command: 'b', - condition: () => !!Markdown, }, { label: 'italic', icon: 'italic', pattern: '_{{text}}_', command: 'i', - condition: () => !!Markdown, }, { label: 'strike', icon: 'strike', pattern: '~{{text}}~', - condition: () => !!Markdown, }, { label: 'strike', icon: 'strike', pattern: '~~{{text}}~~', - condition: () => !!Markdown, }, { label: 'inline_code', icon: 'code', pattern: '`{{text}}`', - condition: () => !!Markdown, }, { label: 'multi_line', icon: 'multiline', pattern: '```\n{{text}}\n``` ', - condition: () => !!Markdown, }, { label: 'KaTeX' as TranslationKey, diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index 0a64b2069a62..0507d5303aa4 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -399,10 +399,6 @@ "API_Embed_Description": "Whether embedded link previews are enabled or not when a user posts a link to a website.", "API_Embed_UserAgent": "Embed Request User Agent", "API_EmbedCacheExpirationDays": "Embed Cache Expiration Days", - "API_EmbedIgnoredHosts": "Embed Ignored Hosts", - "API_EmbedIgnoredHosts_Description": "Comma-separated list of hosts or CIDR addresses, eg. localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16", - "API_EmbedSafePorts": "Safe Ports", - "API_EmbedSafePorts_Description": "Comma-separated list of ports allowed for previewing.", "API_Enable_CORS": "Enable CORS", "API_Enable_Direct_Message_History_EndPoint": "Enable Direct Message History Endpoint", "API_Enable_Direct_Message_History_EndPoint_Description": "This enables the `/api/v1/im.history.others` which allows the viewing of direct messages sent by other users that the caller is not part of.", @@ -1771,7 +1767,6 @@ "EmojiCustomFilesystem_Description": "Specify how emojis are stored.", "Empty_no_agent_selected": "Empty, no agent selected", "Empty_title": "Empty title", - "Use_Legacy_Message_Template": "Use legacy message template", "Enable": "Enable", "Enable_Auto_Away": "Enable Auto Away", "Enable_CSP": "Enable Content-Security-Policy", diff --git a/apps/meteor/server/startup/migrations/v283.ts b/apps/meteor/server/startup/migrations/v283.ts index d3bdb6cda64b..afafacb559cf 100644 --- a/apps/meteor/server/startup/migrations/v283.ts +++ b/apps/meteor/server/startup/migrations/v283.ts @@ -31,6 +31,8 @@ addMigration({ 'IssueLinks_Enabled', 'IssueLinks_Template', 'API_EmbedDisabledFor', + 'API_EmbedIgnoredHosts', + 'API_EmbedSafePorts', ]; Settings.deleteMany({ From 4ffd80ab4ca0423ebddc9a33416f9819126a5269 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 3 Feb 2023 15:20:08 -0300 Subject: [PATCH 04/20] lint --- apps/meteor/app/oembed/server/server.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/meteor/app/oembed/server/server.ts b/apps/meteor/app/oembed/server/server.ts index 11d92bfb3f20..32c75f9035ae 100644 --- a/apps/meteor/app/oembed/server/server.ts +++ b/apps/meteor/app/oembed/server/server.ts @@ -4,7 +4,6 @@ import querystring from 'querystring'; import { camelCase } from 'change-case'; import _ from 'underscore'; import iconv from 'iconv-lite'; -import ipRangeCheck from 'ip-range-check'; import he from 'he'; import jschardet from 'jschardet'; import type { OEmbedUrlContentResult, OEmbedUrlWithMetadata, IMessage, MessageAttachment, OEmbedMeta } from '@rocket.chat/core-typings'; From 1d1a0040db1ffdafea541aff24748bb507de6467 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 3 Feb 2023 15:51:40 -0300 Subject: [PATCH 05/20] removed places where preference for legacy message settings was still being used --- .../app/ui-utils/client/lib/messageContext.ts | 4 ---- .../preferences/PreferencesGlobalSection.tsx | 16 +++------------- .../views/room/components/body/RoomBody.tsx | 18 +----------------- .../components/body/useRoomMessageContext.ts | 3 --- .../Threads/components/ThreadChat.tsx | 8 +------- .../tests/end-to-end/api/00-miscellaneous.js | 1 - .../v1/users/UsersSetPreferenceParamsPOST.ts | 5 ----- 7 files changed, 5 insertions(+), 50 deletions(-) diff --git a/apps/meteor/app/ui-utils/client/lib/messageContext.ts b/apps/meteor/app/ui-utils/client/lib/messageContext.ts index ce15afc1cbd4..3e50863ecd3e 100644 --- a/apps/meteor/app/ui-utils/client/lib/messageContext.ts +++ b/apps/meteor/app/ui-utils/client/lib/messageContext.ts @@ -14,7 +14,6 @@ import type { CommonRoomTemplateInstance } from '../../../ui/client/views/app/li const fields = { 'name': 1, 'username': 1, - 'settings.preferences.useLegacyMessageTemplate': 1, 'settings.preferences.autoImageLoad': 1, 'settings.preferences.saveMobileBandwidth': 1, 'settings.preferences.collapseMediaByDefault': 1, @@ -51,7 +50,6 @@ export const createMessageContext = ({ ), translateLanguage = AutoTranslate.getLanguage(rid), autoImageLoad = getUserPreference(user, 'autoImageLoad'), - useLegacyMessageTemplate = getUserPreference(user, 'useLegacyMessageTemplate'), saveMobileBandwidth = Meteor.Device.isPhone() && getUserPreference(user, 'saveMobileBandwidth'), collapseMediaByDefault = getUserPreference(user, 'collapseMediaByDefault'), showreply = true, @@ -83,7 +81,6 @@ export const createMessageContext = ({ embeddedLayout?: boolean; translateLanguage?: unknown; autoImageLoad?: unknown; - useLegacyMessageTemplate?: unknown; saveMobileBandwidth?: unknown; collapseMediaByDefault?: unknown; showreply?: unknown; @@ -106,7 +103,6 @@ export const createMessageContext = ({ settings: { translateLanguage, autoImageLoad, - useLegacyMessageTemplate, saveMobileBandwidth, collapseMediaByDefault, showreply, diff --git a/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.tsx b/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.tsx index b53249b40a95..7c2410deb9fb 100644 --- a/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.tsx +++ b/apps/meteor/client/views/account/preferences/PreferencesGlobalSection.tsx @@ -1,5 +1,5 @@ import type { SelectOption } from '@rocket.chat/fuselage'; -import { Accordion, Field, FieldGroup, MultiSelect, ToggleSwitch, Callout } from '@rocket.chat/fuselage'; +import { Accordion, Field, FieldGroup, MultiSelect } from '@rocket.chat/fuselage'; import { useUserPreference, useTranslation } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; import React, { useMemo } from 'react'; @@ -11,7 +11,6 @@ const PreferencesGlobalSection = ({ onChange, commitRef, ...props }: FormSection const t = useTranslation(); const userDontAskAgainList = useUserPreference<{ action: string; label: string }[]>('dontAskAgainList'); - const userLegacyMessageTemplate = useUserPreference('useLegacyMessageTemplate'); const options = useMemo( () => (userDontAskAgainList || []).map(({ action, label }) => [action, label]) as SelectOption[], @@ -23,17 +22,15 @@ const PreferencesGlobalSection = ({ onChange, commitRef, ...props }: FormSection const { values, handlers, commit } = useForm( { dontAskAgainList: selectedOptions, - useLegacyMessageTemplate: userLegacyMessageTemplate, }, onChange, ); - const { dontAskAgainList, useLegacyMessageTemplate } = values as { + const { dontAskAgainList } = values as { dontAskAgainList: string[]; - useLegacyMessageTemplate: boolean; }; - const { handleDontAskAgainList, handleUseLegacyMessageTemplate } = handlers; + const { handleDontAskAgainList } = handlers; commitRef.current.global = commit; @@ -51,13 +48,6 @@ const PreferencesGlobalSection = ({ onChange, commitRef, ...props }: FormSection /> - - {t('Use_Legacy_Message_Template')} - - - - - {t('This_is_a_deprecated_feature_alert')} ); diff --git a/apps/meteor/client/views/room/components/body/RoomBody.tsx b/apps/meteor/client/views/room/components/body/RoomBody.tsx index 1d783e7432bc..d0d69a33b08d 100644 --- a/apps/meteor/client/views/room/components/body/RoomBody.tsx +++ b/apps/meteor/client/views/room/components/body/RoomBody.tsx @@ -33,11 +33,9 @@ import MessageListErrorBoundary from '../../MessageList/MessageListErrorBoundary import { useChat } from '../../contexts/ChatContext'; import { useRoom, useRoomSubscription, useRoomMessages } from '../../contexts/RoomContext'; import { useToolboxContext } from '../../contexts/ToolboxContext'; -import { useLegacyMessageEvents } from '../../hooks/useLegacyMessageEvents'; import DropTargetOverlay from './DropTargetOverlay'; import JumpToRecentMessagesBar from './JumpToRecentMessagesBar'; import LeaderBar from './LeaderBar'; -import LegacyMessageTemplateList from './LegacyMessageTemplateList'; import LoadingMessagesIndicator from './LoadingMessagesIndicator'; import NewMessagesButton from './NewMessagesButton'; import RetentionPolicyWarning from './RetentionPolicyWarning'; @@ -65,7 +63,6 @@ const RoomBody = (): ReactElement => { const hideFlexTab = useUserPreference('hideFlexTab'); const hideUsernames = useUserPreference('hideUsernames'); const displayAvatars = useUserPreference('displayAvatars'); - const useLegacyMessageTemplate = useUserPreference('useLegacyMessageTemplate') ?? false; const viewMode = useUserPreference('messageViewMode'); const wrapperRef = useRef(null); @@ -325,19 +322,6 @@ const RoomBody = (): ReactElement => { }; }, [room._id, setUnreadCount]); - useLegacyMessageEvents({ - messageListRef: { - get current() { - if (!useLegacyMessageTemplate) { - return null; - } - - return wrapperRef.current?.querySelector('ul') ?? null; - }, - }, - onRequestScrollToBottom: sendToBottomIfNecessary, - }); - useEffect(() => { const wrapper = wrapperRef.current; @@ -625,7 +609,7 @@ const RoomBody = (): ReactElement => { )} ) : null} - {useLegacyMessageTemplate ? : } + {hasMoreNextMessages ? (
  • {isLoadingMoreMessages ? : null}
  • ) : null} diff --git a/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts b/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts index 3b1ab5c91f3d..77c7aba178be 100644 --- a/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts +++ b/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts @@ -16,7 +16,6 @@ export const useRoomMessageContext = (room: IRoom) => { const { isMobile: mobile } = useLayout(); const translateLanguage = useReactiveValue(useCallback(() => AutoTranslate.getLanguage(rid), [rid])); const autoImageLoad = useUserPreference('autoImageLoad'); - const useLegacyMessageTemplate = useUserPreference('useLegacyMessageTemplate'); const saveMobileBandwidth = useUserPreference('saveMobileBandwidth'); const collapseMediaByDefault = useUserPreference('collapseMediaByDefault'); const hasPermissionDeleteMessage = usePermission('delete-message', rid); @@ -41,7 +40,6 @@ export const useRoomMessageContext = (room: IRoom) => { subscription, translateLanguage, autoImageLoad, - useLegacyMessageTemplate, saveMobileBandwidth: mobile && saveMobileBandwidth, collapseMediaByDefault, showreply: true, @@ -77,7 +75,6 @@ export const useRoomMessageContext = (room: IRoom) => { subscription, translateLanguage, uid, - useLegacyMessageTemplate, useRealName, user, ], diff --git a/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadChat.tsx b/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadChat.tsx index b2d0f1920374..db908e0da6a9 100644 --- a/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadChat.tsx +++ b/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadChat.tsx @@ -105,18 +105,12 @@ const ThreadChat: VFC = ({ mainMessage }) => { const sendToChannelID = useUniqueId(); const t = useTranslation(); - const useLegacyMessageTemplate = useUserPreference('useLegacyMessageTemplate') ?? false; - return ( - {useLegacyMessageTemplate ? ( - - ) : ( - - )} + ; receiveLoginDetectionEmail?: boolean; - useLegacyMessageTemplate?: boolean; idleTimeLimit?: number; }; }; @@ -194,10 +193,6 @@ const UsersSetPreferencesParamsPostSchema = { }, nullable: true, }, - useLegacyMessageTemplate: { - type: 'boolean', - nullable: true, - }, receiveLoginDetectionEmail: { type: 'boolean', nullable: true, From 78d345e11d2f35269dc988b7fef97ec20320e8e3 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 3 Feb 2023 15:58:20 -0300 Subject: [PATCH 06/20] linting --- .../views/room/contextualBar/Threads/components/ThreadChat.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadChat.tsx b/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadChat.tsx index db908e0da6a9..f2d61153708a 100644 --- a/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadChat.tsx +++ b/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadChat.tsx @@ -15,7 +15,6 @@ import { useFileUploadDropTarget } from '../../../components/body/useFileUploadD import { useChat } from '../../../contexts/ChatContext'; import { useRoom, useRoomSubscription } from '../../../contexts/RoomContext'; import { useTabBarClose } from '../../../contexts/ToolboxContext'; -import LegacyThreadMessageList from './LegacyThreadMessageList'; import ThreadMessageList from './ThreadMessageList'; type ThreadChatProps = { From 7a58f072f5d170a43b8123b4c3de916c76eae943 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 3 Feb 2023 16:11:30 -0300 Subject: [PATCH 07/20] removed unused callbacks --- .../client/startup/renderMessage/autolinker.ts | 10 ---------- .../client/startup/renderMessage/index.ts | 3 --- .../client/startup/renderMessage/issuelink.ts | 10 ---------- .../client/startup/renderMessage/markdown.ts | 18 ------------------ 4 files changed, 41 deletions(-) delete mode 100644 apps/meteor/client/startup/renderMessage/autolinker.ts delete mode 100644 apps/meteor/client/startup/renderMessage/issuelink.ts delete mode 100644 apps/meteor/client/startup/renderMessage/markdown.ts diff --git a/apps/meteor/client/startup/renderMessage/autolinker.ts b/apps/meteor/client/startup/renderMessage/autolinker.ts deleted file mode 100644 index 7eecf0b61c9b..000000000000 --- a/apps/meteor/client/startup/renderMessage/autolinker.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Tracker } from 'meteor/tracker'; - -import { callbacks } from '../../../lib/callbacks'; - -Meteor.startup(() => { - Tracker.autorun(() => { - callbacks.remove('renderMessage', 'autolinker'); - }); -}); diff --git a/apps/meteor/client/startup/renderMessage/index.ts b/apps/meteor/client/startup/renderMessage/index.ts index 09eeca80dd1e..ec329d84b530 100644 --- a/apps/meteor/client/startup/renderMessage/index.ts +++ b/apps/meteor/client/startup/renderMessage/index.ts @@ -1,9 +1,6 @@ -import './autolinker'; import './autotranslate'; import './emoji'; import './hexcolor'; import './highlightWords'; -import './issuelink'; import './katex'; -import './markdown'; import './mentionsMessage'; diff --git a/apps/meteor/client/startup/renderMessage/issuelink.ts b/apps/meteor/client/startup/renderMessage/issuelink.ts deleted file mode 100644 index 6e238f2d3cc1..000000000000 --- a/apps/meteor/client/startup/renderMessage/issuelink.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Tracker } from 'meteor/tracker'; - -import { callbacks } from '../../../lib/callbacks'; - -Meteor.startup(() => { - Tracker.autorun(() => { - callbacks.remove('renderMessage', 'issuelink'); - }); -}); diff --git a/apps/meteor/client/startup/renderMessage/markdown.ts b/apps/meteor/client/startup/renderMessage/markdown.ts deleted file mode 100644 index a741b105c42e..000000000000 --- a/apps/meteor/client/startup/renderMessage/markdown.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Tracker } from 'meteor/tracker'; - -import { callbacks } from '../../../lib/callbacks'; - -Meteor.startup(() => { - Tracker.autorun(() => { - const options = { - rootUrl: Meteor.absoluteUrl(), - }; - - import('../../../app/markdown/client').then(({ createMarkdownMessageRenderer }) => { - const renderMessage = createMarkdownMessageRenderer(options); - callbacks.remove('renderMessage', 'markdown'); - callbacks.add('renderMessage', renderMessage, callbacks.priority.HIGH, 'markdown'); - }); - }); -}); From 2093c848c35ecb6e94eed5db30bca2c45fa080e8 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Wed, 8 Feb 2023 15:17:43 -0300 Subject: [PATCH 08/20] removed duplicates --- .../client/messageBox/messageBoxFormatting.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts b/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts index 353a314c2604..b92d23e76c5b 100644 --- a/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts +++ b/apps/meteor/app/ui-message/client/messageBox/messageBoxFormatting.ts @@ -28,12 +28,6 @@ export const formattingButtons: ReadonlyArray = [ pattern: '*{{text}}*', command: 'b', }, - { - label: 'bold', - icon: 'bold', - pattern: '**{{text}}**', - command: 'b', - }, { label: 'italic', icon: 'italic', @@ -45,11 +39,6 @@ export const formattingButtons: ReadonlyArray = [ icon: 'strike', pattern: '~{{text}}~', }, - { - label: 'strike', - icon: 'strike', - pattern: '~~{{text}}~~', - }, { label: 'inline_code', icon: 'code', From 4dac5cde65c367deabe44805093e21b5df4139f1 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Thu, 9 Feb 2023 11:05:14 -0300 Subject: [PATCH 09/20] linting --- apps/meteor/server/startup/migrations/v285.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/server/startup/migrations/v285.ts b/apps/meteor/server/startup/migrations/v285.ts index d2c557229915..79d825f281b9 100644 --- a/apps/meteor/server/startup/migrations/v285.ts +++ b/apps/meteor/server/startup/migrations/v285.ts @@ -39,4 +39,4 @@ addMigration({ _id: { $in: deprecatedSettings }, }); }, -}); \ No newline at end of file +}); From 4013e23b4630050d931694b3694b2312fb30b0d7 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 10:38:05 -0300 Subject: [PATCH 10/20] re-added embed settings --- .../meteor/app/lib/server/startup/settings.ts | 10 ++++++++ apps/meteor/app/oembed/server/server.ts | 24 +++++++++++++++++++ apps/meteor/server/startup/migrations/v287.ts | 4 +--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/apps/meteor/app/lib/server/startup/settings.ts b/apps/meteor/app/lib/server/startup/settings.ts index d7a6e3fd2131..fd302cd4f4ff 100644 --- a/apps/meteor/app/lib/server/startup/settings.ts +++ b/apps/meteor/app/lib/server/startup/settings.ts @@ -1291,6 +1291,16 @@ settingsRegistry.addGroup('Message', function () { public: true, }); + // TODO: deprecate this setting in favor of App + this.add('API_EmbedIgnoredHosts', 'localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16', { + type: 'string', + i18nDescription: 'API_EmbedIgnoredHosts_Description', + }); + // TODO: deprecate this setting in favor of App + this.add('API_EmbedSafePorts', '80, 443', { + type: 'string', + }); + this.add('Message_ErasureType', 'Delete', { type: 'select', public: true, diff --git a/apps/meteor/app/oembed/server/server.ts b/apps/meteor/app/oembed/server/server.ts index 32c75f9035ae..f5071b2238b6 100644 --- a/apps/meteor/app/oembed/server/server.ts +++ b/apps/meteor/app/oembed/server/server.ts @@ -4,6 +4,7 @@ import querystring from 'querystring'; import { camelCase } from 'change-case'; import _ from 'underscore'; import iconv from 'iconv-lite'; +import ipRangeCheck from 'ip-range-check'; import he from 'he'; import jschardet from 'jschardet'; import type { OEmbedUrlContentResult, OEmbedUrlWithMetadata, IMessage, MessageAttachment, OEmbedMeta } from '@rocket.chat/core-typings'; @@ -69,7 +70,30 @@ const getUrlContent = async function (urlObjStr: string | URL.UrlWithStringQuery urlObj = urlObjStr; } + const portsProtocol = new Map( + Object.entries({ + 80: 'http:', + 8080: 'http:', + 443: 'https:', + }), + ); + const parsedUrl = _.pick(urlObj, ['host', 'hash', 'pathname', 'protocol', 'port', 'query', 'search', 'hostname']); + const ignoredHosts = settings.get('API_EmbedIgnoredHosts').replace(/\s/g, '').split(',') || []; + if (parsedUrl.hostname && (ignoredHosts.includes(parsedUrl.hostname) || ipRangeCheck(parsedUrl.hostname, ignoredHosts))) { + throw new Error('invalid host'); + } + + const safePorts = settings.get('API_EmbedSafePorts').replace(/\s/g, '').split(',') || []; + + if (safePorts.length > 0 && parsedUrl.port && !safePorts.includes(parsedUrl.port)) { + throw new Error('invalid/unsafe port'); + } + + if (safePorts.length > 0 && !parsedUrl.port && !safePorts.some((port) => portsProtocol.get(port) === parsedUrl.protocol)) { + throw new Error('invalid/unsafe port'); + } + const data = callbacks.run('oembed:beforeGetUrlContent', { urlObj, parsedUrl, diff --git a/apps/meteor/server/startup/migrations/v287.ts b/apps/meteor/server/startup/migrations/v287.ts index be17bbad6c65..83e9000fbc28 100644 --- a/apps/meteor/server/startup/migrations/v287.ts +++ b/apps/meteor/server/startup/migrations/v287.ts @@ -30,9 +30,7 @@ addMigration({ 'AutoLinker_Phone', 'IssueLinks_Enabled', 'IssueLinks_Template', - 'API_EmbedDisabledFor', - 'API_EmbedIgnoredHosts', - 'API_EmbedSafePorts', + 'API_EmbedDisabledFor' ]; Settings.deleteMany({ From 701f0760a61e30417daba2f19e2eee4bfc458800 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 10:42:01 -0300 Subject: [PATCH 11/20] linting --- apps/meteor/server/startup/migrations/v287.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/server/startup/migrations/v287.ts b/apps/meteor/server/startup/migrations/v287.ts index 83e9000fbc28..44cdad140ee8 100644 --- a/apps/meteor/server/startup/migrations/v287.ts +++ b/apps/meteor/server/startup/migrations/v287.ts @@ -30,7 +30,7 @@ addMigration({ 'AutoLinker_Phone', 'IssueLinks_Enabled', 'IssueLinks_Template', - 'API_EmbedDisabledFor' + 'API_EmbedDisabledFor', ]; Settings.deleteMany({ From 73cbd66acc768819b01a08d1fe02303f55efd173 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 11:04:11 -0300 Subject: [PATCH 12/20] re-added API_EmbedDisabledFor --- apps/meteor/app/lib/server/startup/settings.ts | 8 ++++++++ apps/meteor/app/ui-message/client/message.js | 9 +++++++++ apps/meteor/app/ui-utils/client/lib/messageContext.ts | 4 ++++ .../views/room/components/body/useRoomMessageContext.ts | 3 +++ apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json | 6 ++++++ apps/meteor/server/startup/migrations/v287.ts | 1 - 6 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/meteor/app/lib/server/startup/settings.ts b/apps/meteor/app/lib/server/startup/settings.ts index fd302cd4f4ff..0b96d43c62a5 100644 --- a/apps/meteor/app/lib/server/startup/settings.ts +++ b/apps/meteor/app/lib/server/startup/settings.ts @@ -1291,6 +1291,14 @@ settingsRegistry.addGroup('Message', function () { public: true, }); + // TODO: deprecate this setting in favor of App + this.add('API_EmbedDisabledFor', '', { + type: 'string', + public: true, + i18nDescription: 'API_EmbedDisabledFor_Description', + alert: 'This_is_a_deprecated_feature_alert', + }); + // TODO: deprecate this setting in favor of App this.add('API_EmbedIgnoredHosts', 'localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16', { type: 'string', diff --git a/apps/meteor/app/ui-message/client/message.js b/apps/meteor/app/ui-message/client/message.js index 43fe4765de81..f0bffebb9a52 100644 --- a/apps/meteor/app/ui-message/client/message.js +++ b/apps/meteor/app/ui-message/client/message.js @@ -309,6 +309,15 @@ Template.message.helpers({ return false; } + // check if oembed is disabled for message's sender + if ( + (settings.API_EmbedDisabledFor || '') + .split(',') + .map((username) => username.trim()) + .includes(msg.u && msg.u.username) + ) { + return false; + } return true; }, reactions() { diff --git a/apps/meteor/app/ui-utils/client/lib/messageContext.ts b/apps/meteor/app/ui-utils/client/lib/messageContext.ts index 14f519d7d348..d243f0c9c599 100644 --- a/apps/meteor/app/ui-utils/client/lib/messageContext.ts +++ b/apps/meteor/app/ui-utils/client/lib/messageContext.ts @@ -70,6 +70,8 @@ export const createMessageContext = ({ // eslint-disable-next-line @typescript-eslint/naming-convention API_Embed = settings.get('API_Embed'), // eslint-disable-next-line @typescript-eslint/naming-convention + API_EmbedDisabledFor = settings.get('API_EmbedDisabledFor'), + // eslint-disable-next-line @typescript-eslint/naming-convention Message_GroupingPeriod = settings.get('Message_GroupingPeriod') * 1000, }: { uid?: IUser['_id'] | null; @@ -94,6 +96,7 @@ export const createMessageContext = ({ Message_AllowEditing?: unknown; Message_AllowEditing_BlockEditInMinutes?: unknown; API_Embed?: unknown; + API_EmbedDisabledFor?: unknown; Message_GroupingPeriod?: unknown; } = {}) => { return { @@ -116,6 +119,7 @@ export const createMessageContext = ({ Message_AllowEditing, Message_AllowEditing_BlockEditInMinutes, API_Embed, + API_EmbedDisabledFor, Message_GroupingPeriod, }, } as const; diff --git a/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts b/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts index 77c7aba178be..7c7b9ef457a2 100644 --- a/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts +++ b/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts @@ -28,6 +28,7 @@ export const useRoomMessageContext = (room: IRoom) => { const allowEditing = useSetting('Message_AllowEditing'); const blockEditInMinutes = useSetting('Message_AllowEditing_BlockEditInMinutes'); const embed = useSetting('API_Embed'); + const embedDisabledFor = useSetting('API_EmbedDisabledFor'); const groupingPeriod = useSetting('Message_GroupingPeriod') as number; return useMemo( @@ -53,6 +54,7 @@ export const useRoomMessageContext = (room: IRoom) => { Message_AllowEditing: allowEditing, Message_AllowEditing_BlockEditInMinutes: blockEditInMinutes, API_Embed: embed, + API_EmbedDisabledFor: embedDisabledFor, Message_GroupingPeriod: groupingPeriod * 1000, }), [ @@ -64,6 +66,7 @@ export const useRoomMessageContext = (room: IRoom) => { collapseMediaByDefault, displayRoles, embed, + embedDisabledFor, groupingPeriod, hasPermissionDeleteMessage, hasPermissionDeleteOwnMessage, diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index f8cb94120e0b..23cd23ddf2f5 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -399,6 +399,12 @@ "API_Drupal_URL_Description": "Example: https://domain.com (excluding trailing slash)", "API_Embed": "Embed Link Previews", "API_Embed_Description": "Whether embedded link previews are enabled or not when a user posts a link to a website.", + "API_EmbedDisabledFor": "Disable Embed for Users", + "API_EmbedDisabledFor_Description": "Comma-separated list of usernames to disable the embedded link previews.", + "API_EmbedIgnoredHosts": "Embed Ignored Hosts", + "API_EmbedIgnoredHosts_Description": "Comma-separated list of hosts or CIDR addresses, eg. localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16", + "API_EmbedSafePorts": "Safe Ports", + "API_EmbedSafePorts_Description": "Comma-separated list of ports allowed for previewing.", "API_Embed_UserAgent": "Embed Request User Agent", "API_EmbedCacheExpirationDays": "Embed Cache Expiration Days", "API_Enable_CORS": "Enable CORS", diff --git a/apps/meteor/server/startup/migrations/v287.ts b/apps/meteor/server/startup/migrations/v287.ts index 44cdad140ee8..984d9b8a1dc5 100644 --- a/apps/meteor/server/startup/migrations/v287.ts +++ b/apps/meteor/server/startup/migrations/v287.ts @@ -30,7 +30,6 @@ addMigration({ 'AutoLinker_Phone', 'IssueLinks_Enabled', 'IssueLinks_Template', - 'API_EmbedDisabledFor', ]; Settings.deleteMany({ From 0abd45dcc063b2fa93f8de523a8bd9180a6fa65c Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 11:18:52 -0300 Subject: [PATCH 13/20] removed autolinker and issuelinks --- apps/meteor/app/autolinker/client/client.js | 58 --------------------- apps/meteor/app/autolinker/client/index.js | 1 - apps/meteor/app/issuelinks/client/client.js | 14 ----- apps/meteor/app/issuelinks/client/index.js | 1 - 4 files changed, 74 deletions(-) delete mode 100644 apps/meteor/app/autolinker/client/client.js delete mode 100644 apps/meteor/app/autolinker/client/index.js delete mode 100644 apps/meteor/app/issuelinks/client/client.js delete mode 100644 apps/meteor/app/issuelinks/client/index.js diff --git a/apps/meteor/app/autolinker/client/client.js b/apps/meteor/app/autolinker/client/client.js deleted file mode 100644 index a3e6d77d3e21..000000000000 --- a/apps/meteor/app/autolinker/client/client.js +++ /dev/null @@ -1,58 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Random } from 'meteor/random'; -import Autolinker from 'autolinker'; -import { escapeRegExp } from '@rocket.chat/string-helpers'; - -export const createAutolinkerMessageRenderer = - ({ phone, ...config }) => - (message) => { - if (!message.html?.trim()) { - return message; - } - - let msgParts; - let regexTokens; - if (message.tokens && message.tokens.length) { - regexTokens = new RegExp(`(${(message.tokens || []).map(({ token }) => escapeRegExp(token))})`, 'g'); - msgParts = message.html.split(regexTokens); - } else { - msgParts = [message.html]; - } - - message.html = msgParts - .map((msgPart) => { - if (regexTokens && regexTokens.test(msgPart)) { - return msgPart; - } - - const muttableConfig = { - ...config, - phone: false, - stripTrailingSlash: false, - replaceFn: (match) => { - const token = `=!=${Random.id()}=!=`; - const tag = match.buildTag(); - - if (~match.matchedText.indexOf(Meteor.absoluteUrl())) { - tag.setAttr('target', ''); - } - - message.tokens = message.tokens ?? []; - message.tokens.push({ - token, - text: tag.toAnchorString(), - }); - return token; - }, - }; - - const autolinkerMsg = Autolinker.link(msgPart, muttableConfig); - - muttableConfig.phone = phone; - - return phone ? Autolinker.link(autolinkerMsg, muttableConfig) : autolinkerMsg; - }) - .join(''); - - return message; - }; diff --git a/apps/meteor/app/autolinker/client/index.js b/apps/meteor/app/autolinker/client/index.js deleted file mode 100644 index 4dbc40111253..000000000000 --- a/apps/meteor/app/autolinker/client/index.js +++ /dev/null @@ -1 +0,0 @@ -export { createAutolinkerMessageRenderer } from './client'; diff --git a/apps/meteor/app/issuelinks/client/client.js b/apps/meteor/app/issuelinks/client/client.js deleted file mode 100644 index 0a149ba1dfb6..000000000000 --- a/apps/meteor/app/issuelinks/client/client.js +++ /dev/null @@ -1,14 +0,0 @@ -export const createIssueLinksMessageRenderer = - ({ template }) => - (message) => { - if (!message.html?.trim()) { - return message; - } - - message.html = message.html.replace(/(?:^|\s|\n)(#[0-9]+)\b/g, (match, issueNumber) => { - const url = template.replace('%s', issueNumber.substring(1)); - return match.replace(issueNumber, `${issueNumber}`); - }); - - return message; - }; diff --git a/apps/meteor/app/issuelinks/client/index.js b/apps/meteor/app/issuelinks/client/index.js deleted file mode 100644 index bd72fbfb085e..000000000000 --- a/apps/meteor/app/issuelinks/client/index.js +++ /dev/null @@ -1 +0,0 @@ -export { createIssueLinksMessageRenderer } from './client'; From aa92f8038cbbc9020dc034f2018b669e4c1e1fa6 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 12:28:59 -0300 Subject: [PATCH 14/20] removed snippeted properties from messages --- apps/meteor/app/api/server/lib/messages.ts | 60 -------------- apps/meteor/app/api/server/v1/chat.js | 57 +------------ .../server/functions/upsertPermissions.ts | 1 - .../app/message-snippet/client/index.js | 7 -- .../message-snippet/client/lib/collections.js | 3 - .../app/message-snippet/client/messageType.js | 18 ----- .../client/page/snippetPage.html | 21 ----- .../client/page/snippetPage.js | 44 ---------- .../client/page/stylesheets/snippetPage.css | 62 -------------- .../message-snippet/client/snippetMessage.js | 27 ------- .../tabBar/views/snippetedMessages.html | 24 ------ .../client/tabBar/views/snippetedMessages.js | 80 ------------------- .../app/message-snippet/server/index.js | 2 - .../server/methods/snippetMessage.js | 55 ------------- .../app/message-snippet/server/requests.js | 63 --------------- .../app/models/server/models/Messages.js | 25 ------ apps/meteor/app/models/server/models/Rooms.js | 18 ----- .../meteor/app/ui-message/client/message.html | 3 - apps/meteor/app/ui-message/client/message.js | 4 - apps/meteor/client/importPackages.ts | 1 - .../rocketchat-i18n/i18n/en.i18n.json | 3 - apps/meteor/server/importPackages.ts | 1 - apps/meteor/server/models/raw/Messages.ts | 10 --- apps/meteor/server/startup/migrations/v287.ts | 19 ++++- apps/meteor/tests/end-to-end/api/05-chat.js | 54 ------------- .../src/models/IMessagesModel.ts | 2 - 26 files changed, 19 insertions(+), 645 deletions(-) delete mode 100644 apps/meteor/app/message-snippet/client/index.js delete mode 100644 apps/meteor/app/message-snippet/client/lib/collections.js delete mode 100644 apps/meteor/app/message-snippet/client/messageType.js delete mode 100644 apps/meteor/app/message-snippet/client/page/snippetPage.html delete mode 100644 apps/meteor/app/message-snippet/client/page/snippetPage.js delete mode 100644 apps/meteor/app/message-snippet/client/page/stylesheets/snippetPage.css delete mode 100644 apps/meteor/app/message-snippet/client/snippetMessage.js delete mode 100644 apps/meteor/app/message-snippet/client/tabBar/views/snippetedMessages.html delete mode 100644 apps/meteor/app/message-snippet/client/tabBar/views/snippetedMessages.js delete mode 100644 apps/meteor/app/message-snippet/server/index.js delete mode 100644 apps/meteor/app/message-snippet/server/methods/snippetMessage.js delete mode 100644 apps/meteor/app/message-snippet/server/requests.js diff --git a/apps/meteor/app/api/server/lib/messages.ts b/apps/meteor/app/api/server/lib/messages.ts index f6e6ab2cfa72..a4f28f9680f7 100644 --- a/apps/meteor/app/api/server/lib/messages.ts +++ b/apps/meteor/app/api/server/lib/messages.ts @@ -82,66 +82,6 @@ export async function findStarredMessages({ }; } -export async function findSnippetedMessageById({ uid, messageId }: { uid: string; messageId: string }): Promise { - if (!uid) { - throw new Error('invalid-user'); - } - - const snippet = await Messages.findOne({ _id: messageId, snippeted: true }); - - if (!snippet) { - throw new Error('invalid-message'); - } - - const room = await Rooms.findOneById(snippet.rid); - - if (!room) { - throw new Error('invalid-message'); - } - - if (!(await canAccessRoomAsync(room, { _id: uid }))) { - throw new Error('error-not-allowed'); - } - - return snippet; -} - -export async function findSnippetedMessages({ - uid, - roomId, - pagination: { offset, count, sort }, -}: { - uid: string; - roomId: string; - pagination: { offset: number; count: number; sort: FindOptions['sort'] }; -}): Promise<{ - messages: IMessage[]; - count: number; - offset: number; - total: number; -}> { - const room = await Rooms.findOneById(roomId); - - if (!room || !(await canAccessRoomAsync(room, { _id: uid }))) { - throw new Error('error-not-allowed'); - } - - const { cursor, totalCount } = Messages.findSnippetedByRoom(roomId, { - sort: sort || { ts: -1 }, - skip: offset, - limit: count, - }); - - const [messages, total] = await Promise.all([cursor.toArray(), totalCount]); - - return { - messages, - count: messages.length, - offset, - total, - }; -} - export async function findDiscussionsFromRoom({ uid, roomId, diff --git a/apps/meteor/app/api/server/v1/chat.js b/apps/meteor/app/api/server/v1/chat.js index 73f4b6931ddc..ab623563eee7 100644 --- a/apps/meteor/app/api/server/v1/chat.js +++ b/apps/meteor/app/api/server/v1/chat.js @@ -14,13 +14,7 @@ import Rooms from '../../../models/server/models/Rooms'; import Users from '../../../models/server/models/Users'; import Subscriptions from '../../../models/server/models/Subscriptions'; import { settings } from '../../../settings/server'; -import { - findMentionedMessages, - findStarredMessages, - findSnippetedMessageById, - findSnippetedMessages, - findDiscussionsFromRoom, -} from '../lib/messages'; +import { findMentionedMessages, findStarredMessages, findDiscussionsFromRoom } from '../lib/messages'; API.v1.addRoute( 'chat.delete', @@ -786,55 +780,6 @@ API.v1.addRoute( }, ); -API.v1.addRoute( - 'chat.getSnippetedMessageById', - { authRequired: true }, - { - get() { - const { messageId } = this.queryParams; - - if (!messageId) { - throw new Meteor.Error('error-invalid-params', 'The required "messageId" query param is missing.'); - } - const message = Promise.await( - findSnippetedMessageById({ - uid: this.userId, - messageId, - }), - ); - return API.v1.success(message); - }, - }, -); - -API.v1.addRoute( - 'chat.getSnippetedMessages', - { authRequired: true }, - { - get() { - const { roomId } = this.queryParams; - const { sort } = this.parseJsonQuery(); - const { offset, count } = this.getPaginationItems(); - - if (!roomId) { - throw new Meteor.Error('error-invalid-params', 'The required "roomId" query param is missing.'); - } - const messages = Promise.await( - findSnippetedMessages({ - uid: this.userId, - roomId, - pagination: { - offset, - count, - sort, - }, - }), - ); - return API.v1.success(messages); - }, - }, -); - API.v1.addRoute( 'chat.getDiscussions', { authRequired: true }, diff --git a/apps/meteor/app/authorization/server/functions/upsertPermissions.ts b/apps/meteor/app/authorization/server/functions/upsertPermissions.ts index 16519b9effe5..33ca8d1ec8e0 100644 --- a/apps/meteor/app/authorization/server/functions/upsertPermissions.ts +++ b/apps/meteor/app/authorization/server/functions/upsertPermissions.ts @@ -209,7 +209,6 @@ export const upsertPermissions = async (): Promise => { { _id: 'manage-sounds', roles: ['admin'] }, { _id: 'access-mailer', roles: ['admin'] }, { _id: 'pin-message', roles: ['owner', 'moderator', 'admin'] }, - { _id: 'snippet-message', roles: ['owner', 'moderator', 'admin'] }, { _id: 'mobile-upload-file', roles: ['user', 'admin'] }, { _id: 'send-mail', roles: ['admin'] }, { _id: 'view-federation-data', roles: ['admin'] }, diff --git a/apps/meteor/app/message-snippet/client/index.js b/apps/meteor/app/message-snippet/client/index.js deleted file mode 100644 index e1d776684406..000000000000 --- a/apps/meteor/app/message-snippet/client/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import './messageType'; -import './snippetMessage'; -import './page/snippetPage.html'; -import './page/snippetPage'; -import './tabBar/views/snippetedMessages.html'; -import './tabBar/views/snippetedMessages'; -import './page/stylesheets/snippetPage.css'; diff --git a/apps/meteor/app/message-snippet/client/lib/collections.js b/apps/meteor/app/message-snippet/client/lib/collections.js deleted file mode 100644 index ff80211fc3a3..000000000000 --- a/apps/meteor/app/message-snippet/client/lib/collections.js +++ /dev/null @@ -1,3 +0,0 @@ -import { Mongo } from 'meteor/mongo'; - -export const SnippetedMessages = new Mongo.Collection('rocketchat_snippeted_message'); diff --git a/apps/meteor/app/message-snippet/client/messageType.js b/apps/meteor/app/message-snippet/client/messageType.js deleted file mode 100644 index ccc2075553cc..000000000000 --- a/apps/meteor/app/message-snippet/client/messageType.js +++ /dev/null @@ -1,18 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { escapeHTML } from '@rocket.chat/string-helpers'; - -import { MessageTypes } from '../../ui-utils'; - -Meteor.startup(function () { - MessageTypes.registerType({ - id: 'message_snippeted', - system: true, - message: 'Snippeted_a_message', - data(message) { - const snippetLink = `${escapeHTML( - message.snippetName, - )}`; - return { snippetLink }; - }, - }); -}); diff --git a/apps/meteor/app/message-snippet/client/page/snippetPage.html b/apps/meteor/app/message-snippet/client/page/snippetPage.html deleted file mode 100644 index 139c9ae9210a..000000000000 --- a/apps/meteor/app/message-snippet/client/page/snippetPage.html +++ /dev/null @@ -1,21 +0,0 @@ - diff --git a/apps/meteor/app/message-snippet/client/page/snippetPage.js b/apps/meteor/app/message-snippet/client/page/snippetPage.js deleted file mode 100644 index 0cd662305e7d..000000000000 --- a/apps/meteor/app/message-snippet/client/page/snippetPage.js +++ /dev/null @@ -1,44 +0,0 @@ -import { FlowRouter } from 'meteor/kadira:flow-router'; -import { ReactiveVar } from 'meteor/reactive-var'; -import { Template } from 'meteor/templating'; -import moment from 'moment'; - -import { settings } from '../../../settings'; -import { Markdown } from '../../../markdown/client'; -import { APIClient } from '../../../utils/client'; -import { formatTime } from '../../../../client/lib/utils/formatTime'; - -Template.snippetPage.helpers({ - snippet() { - return Template.instance().message.get(); - }, - snippetContent() { - const message = Template.instance().message.get(); - if (message === undefined) { - return null; - } - message.html = message.msg; - const markdown = Markdown.parse(message); - return markdown.tokens[0].text; - }, - date() { - const snippet = Template.instance().message.get(); - if (snippet !== undefined) { - return moment(snippet.ts).format(settings.get('Message_DateFormat')); - } - }, - time() { - const snippet = Template.instance().message.get(); - if (snippet !== undefined) { - return formatTime(snippet.ts); - } - }, -}); - -Template.snippetPage.onCreated(async function () { - const snippetId = FlowRouter.getParam('snippetId'); - this.message = new ReactiveVar({}); - - const { message } = await APIClient.get('/v1/chat.getSnippetedMessageById', { messageId: snippetId }); - this.message.set(message); -}); diff --git a/apps/meteor/app/message-snippet/client/page/stylesheets/snippetPage.css b/apps/meteor/app/message-snippet/client/page/stylesheets/snippetPage.css deleted file mode 100644 index 1b3462721efd..000000000000 --- a/apps/meteor/app/message-snippet/client/page/stylesheets/snippetPage.css +++ /dev/null @@ -1,62 +0,0 @@ -:root { - --snippet-page-left-border-size: 30px; - --snippet-page-top-border-size: 20px; - --snippet-informations-height: 40px; - --snippet-page-right-border-size: 30px; -} - -.snippet-page { - overflow-x: hidden; - overflow-y: auto; - - width: auto; - height: 100%; - padding-top: var(--snippet-page-top-border-size); - padding-right: var(--snippet-page-right-border-size); - padding-left: var(--snippet-page-left-border-size); - - & pre code, - & h1, - & span { - user-select: all; - } - - & .snippet-informations { - display: inline-block; - - width: 100%; - height: 60px; - - & .avatar { - display: block; - float: left; - clear: left; - - margin-right: 10px; - } - - & .username { - display: block; - - width: 100%; - } - - & .snippet-filename { - display: block; - - width: 100%; - - font-weight: bold; - } - } - - & .info { - color: darkgrey; - - font-style: italic; - } - - & .download-button { - float: right; - } -} diff --git a/apps/meteor/app/message-snippet/client/snippetMessage.js b/apps/meteor/app/message-snippet/client/snippetMessage.js deleted file mode 100644 index 3641086975ad..000000000000 --- a/apps/meteor/app/message-snippet/client/snippetMessage.js +++ /dev/null @@ -1,27 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -import { ChatMessage, Subscriptions } from '../../models/client'; - -Meteor.methods({ - snippetMessage(message) { - if (typeof Meteor.userId() === 'undefined' || Meteor.userId() === null) { - return false; - } - - const subscription = Subscriptions.findOne({ 'rid': message.rid, 'u._id': Meteor.userId() }); - - if (subscription === undefined) { - return false; - } - ChatMessage.update( - { - _id: message._id, - }, - { - $set: { - snippeted: true, - }, - }, - ); - }, -}); diff --git a/apps/meteor/app/message-snippet/client/tabBar/views/snippetedMessages.html b/apps/meteor/app/message-snippet/client/tabBar/views/snippetedMessages.html deleted file mode 100644 index 2c047fbb9d34..000000000000 --- a/apps/meteor/app/message-snippet/client/tabBar/views/snippetedMessages.html +++ /dev/null @@ -1,24 +0,0 @@ - diff --git a/apps/meteor/app/message-snippet/client/tabBar/views/snippetedMessages.js b/apps/meteor/app/message-snippet/client/tabBar/views/snippetedMessages.js deleted file mode 100644 index 48da295d07bc..000000000000 --- a/apps/meteor/app/message-snippet/client/tabBar/views/snippetedMessages.js +++ /dev/null @@ -1,80 +0,0 @@ -import _ from 'underscore'; -import { ReactiveVar } from 'meteor/reactive-var'; -import { Template } from 'meteor/templating'; -import { Mongo } from 'meteor/mongo'; - -import { createMessageContext } from '../../../../ui-utils/client/lib/messageContext'; -import { APIClient } from '../../../../utils/client'; -import { Messages } from '../../../../models/client'; -import { upsertMessageBulk } from '../../../../ui-utils/client/lib/RoomHistoryManager'; - -const LIMIT_DEFAULT = 50; - -Template.snippetedMessages.helpers({ - hasMessages() { - return Template.instance().messages.find().count(); - }, - messages() { - const instance = Template.instance(); - return instance.messages.find({}, { limit: instance.limit.get(), sort: { ts: -1 } }); - }, - hasMore() { - return Template.instance().hasMore.get(); - }, - messageContext: createMessageContext, -}); - -Template.snippetedMessages.onCreated(function () { - this.rid = this.data.rid; - this.hasMore = new ReactiveVar(true); - this.messages = new Mongo.Collection(null); - this.limit = new ReactiveVar(LIMIT_DEFAULT); - - this.autorun(() => { - const query = { - _hidden: { $ne: true }, - snippeted: true, - rid: this.rid, - }; - - this.cursor && this.cursor.stop(); - - this.limit.set(LIMIT_DEFAULT); - - this.cursor = Messages.find(query).observe({ - added: ({ _id, ...message }) => { - this.messages.upsert({ _id }, message); - }, - changed: ({ _id, ...message }) => { - this.messages.upsert({ _id }, message); - }, - removed: ({ _id }) => { - this.messages.remove({ _id }); - }, - }); - }); - - this.autorun(async () => { - const limit = this.limit.get(); - const { messages, total } = await APIClient.get('/v1/chat.getSnippetedMessages', { - roomId: this.rid, - count: limit, - }); - - upsertMessageBulk({ msgs: messages }, this.messages); - - this.hasMore.set(total > limit); - }); -}); - -Template.snippetedMessages.onDestroyed(function () { - this.cursor.stop(); -}); - -Template.snippetedMessages.events({ - 'scroll .js-list': _.throttle(function (e, instance) { - if (e.target.scrollTop >= e.target.scrollHeight - e.target.clientHeight && instance.hasMore.get()) { - return instance.limit.set(instance.limit.get() + 50); - } - }, 200), -}); diff --git a/apps/meteor/app/message-snippet/server/index.js b/apps/meteor/app/message-snippet/server/index.js deleted file mode 100644 index 7ed8e7bdc691..000000000000 --- a/apps/meteor/app/message-snippet/server/index.js +++ /dev/null @@ -1,2 +0,0 @@ -import './methods/snippetMessage'; -import './requests'; diff --git a/apps/meteor/app/message-snippet/server/methods/snippetMessage.js b/apps/meteor/app/message-snippet/server/methods/snippetMessage.js deleted file mode 100644 index 987c3102c71d..000000000000 --- a/apps/meteor/app/message-snippet/server/methods/snippetMessage.js +++ /dev/null @@ -1,55 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -import { Subscriptions, Messages, Users, Rooms } from '../../../models/server'; -import { settings } from '../../../settings/server'; -import { callbacks } from '../../../../lib/callbacks'; -import { isTheLastMessage } from '../../../lib'; - -Meteor.methods({ - snippetMessage(message, filename) { - if (Meteor.userId() == null) { - // noinspection JSUnresolvedFunction - throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'snippetMessage' }); - } - - const room = Rooms.findOne({ _id: message.rid }); - - if (typeof room === 'undefined' || room === null) { - return false; - } - - const subscription = Subscriptions.findOneByRoomIdAndUserId(message.rid, Meteor.userId(), { - fields: { _id: 1 }, - }); - if (!subscription) { - return false; - } - - const me = Users.findOneById(Meteor.userId()); - - // If we keep history of edits, insert a new message to store history information - if (settings.get('Message_KeepHistory')) { - Messages.cloneAndSaveAsHistoryById(message._id, me); - } - - message.snippeted = true; - message.snippetedAt = Date.now; - message.snippetedBy = { - _id: Meteor.userId(), - username: me.username, - }; - - message = callbacks.run('beforeSaveMessage', message); - - // Create the SnippetMessage - Messages.setSnippetedByIdAndUserId(message, filename, message.snippetedBy, message.snippeted, Date.now, filename); - if (isTheLastMessage(room, message)) { - Rooms.setLastMessageSnippeted(room._id, message, filename, message.snippetedBy, message.snippeted, Date.now, filename); - } - - Messages.createWithTypeRoomIdMessageAndUser('message_snippeted', message.rid, '', me, { - snippetId: message._id, - snippetName: filename, - }); - }, -}); diff --git a/apps/meteor/app/message-snippet/server/requests.js b/apps/meteor/app/message-snippet/server/requests.js deleted file mode 100644 index 63f74bf59a00..000000000000 --- a/apps/meteor/app/message-snippet/server/requests.js +++ /dev/null @@ -1,63 +0,0 @@ -import { WebApp } from 'meteor/webapp'; -import { Cookies } from 'meteor/ostrio:cookies'; - -import { Users, Rooms, Messages } from '../../models/server'; - -WebApp.connectHandlers.use('/snippet/download', function (req, res) { - let rawCookies; - let token; - let uid; - const cookie = new Cookies(); - - if (req.headers && req.headers.cookie !== null) { - rawCookies = req.headers.cookie; - } - - if (rawCookies !== null) { - uid = cookie.get('rc_uid', rawCookies); - } - - if (rawCookies !== null) { - token = cookie.get('rc_token', rawCookies); - } - - if (uid === null) { - uid = req.query.rc_uid; - token = req.query.rc_token; - } - - const user = Users.findOneByIdAndLoginToken(uid, token); - - if (!(uid && token && user)) { - res.writeHead(403); - res.end(); - return false; - } - const match = /^\/([^\/]+)\/(.*)/.exec(req.url); - - if (match[1]) { - const snippet = Messages.findOne({ - _id: match[1], - snippeted: true, - }); - const room = Rooms.findOne({ _id: snippet.rid, usernames: { $in: [user.username] } }); - if (room === undefined) { - res.writeHead(403); - res.end(); - return false; - } - - res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(snippet.snippetName)}`); - res.setHeader('Content-Type', 'application/octet-stream'); - - // Removing the ``` contained in the msg. - const snippetContent = snippet.msg.substr(3, snippet.msg.length - 6); - res.setHeader('Content-Length', snippetContent.length); - res.write(snippetContent); - res.end(); - return; - } - - res.writeHead(404); - res.end(); -}); diff --git a/apps/meteor/app/models/server/models/Messages.js b/apps/meteor/app/models/server/models/Messages.js index e570c67ed779..5b02eac244d8 100644 --- a/apps/meteor/app/models/server/models/Messages.js +++ b/apps/meteor/app/models/server/models/Messages.js @@ -21,7 +21,6 @@ export class Messages extends Base { this.tryEnsureIndex({ 'file._id': 1 }, { sparse: true }); this.tryEnsureIndex({ 'mentions.username': 1 }, { sparse: true }); this.tryEnsureIndex({ pinned: 1 }, { sparse: true }); - this.tryEnsureIndex({ snippeted: 1 }, { sparse: true }); this.tryEnsureIndex({ location: '2dsphere' }); this.tryEnsureIndex({ slackTs: 1, slackBotId: 1 }, { sparse: true }); this.tryEnsureIndex({ unread: 1 }, { sparse: true }); @@ -618,30 +617,6 @@ export class Messages extends Base { return this.update(query, update); } - setSnippetedByIdAndUserId(message, snippetName, snippetedBy, snippeted, snippetedAt) { - if (snippeted == null) { - snippeted = true; - } - if (snippetedAt == null) { - snippetedAt = 0; - } - const query = { _id: message._id }; - - const msg = `\`\`\`${message.msg}\`\`\``; - - const update = { - $set: { - msg, - snippeted, - snippetedAt: snippetedAt || new Date(), - snippetedBy, - snippetName, - }, - }; - - return this.update(query, update); - } - setUrlsById(_id, urls) { const query = { _id }; diff --git a/apps/meteor/app/models/server/models/Rooms.js b/apps/meteor/app/models/server/models/Rooms.js index 703cf3b28ec9..c8ad0ead74b1 100644 --- a/apps/meteor/app/models/server/models/Rooms.js +++ b/apps/meteor/app/models/server/models/Rooms.js @@ -125,24 +125,6 @@ export class Rooms extends Base { return this.update(query, update); } - setLastMessageSnippeted(roomId, message, snippetName, snippetedBy, snippeted, snippetedAt) { - const query = { _id: roomId }; - - const msg = `\`\`\`${message.msg}\`\`\``; - - const update = { - $set: { - 'lastMessage.msg': msg, - 'lastMessage.snippeted': snippeted, - 'lastMessage.snippetedAt': snippetedAt || new Date(), - 'lastMessage.snippetedBy': snippetedBy, - 'lastMessage.snippetName': snippetName, - }, - }; - - return this.update(query, update); - } - setLastMessagePinned(roomId, pinnedBy, pinned, pinnedAt) { const query = { _id: roomId }; diff --git a/apps/meteor/app/ui-message/client/message.html b/apps/meteor/app/ui-message/client/message.html index f1ce01f8e126..f9fbb46ed268 100644 --- a/apps/meteor/app/ui-message/client/message.html +++ b/apps/meteor/app/ui-message/client/message.html @@ -97,9 +97,6 @@ {{/if}}
    - {{#if isSnippet}} -
    {{_ "Snippet_name"}}: {{snippetName}}
    - {{/if}} {{#if msg.blocks}}
    {{> Blocks blocks=msg.blocks rid=msg.rid mid=msg._id}} diff --git a/apps/meteor/app/ui-message/client/message.js b/apps/meteor/app/ui-message/client/message.js index f0bffebb9a52..8946b33b2e87 100644 --- a/apps/meteor/app/ui-message/client/message.js +++ b/apps/meteor/app/ui-message/client/message.js @@ -446,10 +446,6 @@ Template.message.helpers({ messageActions() { return Template.instance().actions.get(); }, - isSnippet() { - const { msg } = this; - return msg.actionContext === 'snippeted'; - }, isThreadReply() { const { groupable, diff --git a/apps/meteor/client/importPackages.ts b/apps/meteor/client/importPackages.ts index 3dc430e1eda6..3843b7fcd9e2 100644 --- a/apps/meteor/client/importPackages.ts +++ b/apps/meteor/client/importPackages.ts @@ -29,7 +29,6 @@ import '../app/logger/client'; import '../app/markdown/client'; import '../app/message-attachments/client'; import '../app/message-mark-as-unread/client'; -import '../app/message-snippet/client'; import '../app/nextcloud/client'; import '../app/oauth2-server-config/client'; import '../app/oembed/client'; diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index 23cd23ddf2f5..8ee6354606d8 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -4450,10 +4450,7 @@ "SMTP_Test_Button": "Test SMTP Settings", "SMTP_Username": "SMTP Username", "Snippet_Added": "Created on %s", - "Snippet_Messages": "Snippet Messages", "Snippet_name": "Snippet name", - "snippet-message": "Snippet Message", - "snippet-message_description": "Permission to create snippet message", "Snippeted_a_message": "Created a snippet __snippetLink__", "Social_Network": "Social Network", "Some_ideas_to_get_you_started": "Some ideas to get you started", diff --git a/apps/meteor/server/importPackages.ts b/apps/meteor/server/importPackages.ts index a15dfce24d11..c51a5ade1732 100644 --- a/apps/meteor/server/importPackages.ts +++ b/apps/meteor/server/importPackages.ts @@ -49,7 +49,6 @@ import '../app/markdown/server'; import '../app/mentions/server'; import '../app/message-mark-as-unread/server'; import '../app/message-pin/server'; -import '../app/message-snippet/server'; import '../app/message-star/server'; import '../app/nextcloud/server'; import '../app/oauth2-server-config/server'; diff --git a/apps/meteor/server/models/raw/Messages.ts b/apps/meteor/server/models/raw/Messages.ts index fcd65df40493..f0dcc66ab7ef 100644 --- a/apps/meteor/server/models/raw/Messages.ts +++ b/apps/meteor/server/models/raw/Messages.ts @@ -64,16 +64,6 @@ export class MessagesRaw extends BaseRaw implements IMessagesModel { return this.findPaginated(query, options); } - findSnippetedByRoom(roomId: IRoom['_id'], options: FindOptions): FindPaginated> { - const query: Filter = { - _hidden: { $ne: true }, - snippeted: true, - rid: roomId, - }; - - return this.findPaginated(query, options); - } - // TODO: do we need this? currently not used anywhere findDiscussionsByRoom(rid: IRoom['_id'], options: FindOptions): FindCursor { const query: Filter = { rid, drid: { $exists: true } }; diff --git a/apps/meteor/server/startup/migrations/v287.ts b/apps/meteor/server/startup/migrations/v287.ts index 984d9b8a1dc5..c6f463370eaa 100644 --- a/apps/meteor/server/startup/migrations/v287.ts +++ b/apps/meteor/server/startup/migrations/v287.ts @@ -1,6 +1,7 @@ -import { Settings } from '@rocket.chat/models'; +import { Messages, Settings } from '@rocket.chat/models'; import { addMigration } from '../../lib/migrations'; +import { upsertPermissions } from '../../../app/authorization/server/functions/upsertPermissions'; addMigration({ version: 287, @@ -35,5 +36,21 @@ addMigration({ Settings.deleteMany({ _id: { $in: deprecatedSettings }, }); + + Messages.updateMany( + { + snippeted: true, + }, + { + $unset: { + snippeted: 1, + snippetedBy: 1, + snippetedAt: 1, + snippetName: 1, + }, + }, + ); + + upsertPermissions(); }, }); diff --git a/apps/meteor/tests/end-to-end/api/05-chat.js b/apps/meteor/tests/end-to-end/api/05-chat.js index 84cefdd207ad..c46f4913f2a6 100644 --- a/apps/meteor/tests/end-to-end/api/05-chat.js +++ b/apps/meteor/tests/end-to-end/api/05-chat.js @@ -1988,47 +1988,6 @@ describe('[Chat]', function () { }); }); - describe('[/chat.getSnippetedMessages]', () => { - it('should return an error when the required "roomId" parameter is not sent', (done) => { - request - .get(api('chat.getSnippetedMessages')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(400) - .expect((res) => { - expect(res.body).to.have.property('success', false); - expect(res.body.errorType).to.be.equal('error-invalid-params'); - }) - .end(done); - }); - - it('should return an error when the roomId is invalid', (done) => { - request - .get(api('chat.getSnippetedMessages?roomId=invalid-room')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(400) - .expect((res) => { - expect(res.body).to.have.property('success', false); - expect(res.body.error).to.be.equal('error-not-allowed'); - }) - .end(done); - }); - - it('should return an error when the messageId is invalid', (done) => { - request - .get(api('chat.getSnippetedMessageById?messageId=invalid-id')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(400) - .expect((res) => { - expect(res.body).to.have.property('success', false); - expect(res.body.error).to.be.equal('invalid-message'); - }) - .end(done); - }); - }); - describe('[/chat.getDiscussions]', () => { const messageText = 'Message to create discussion'; let testChannel; @@ -2173,19 +2132,6 @@ describe('[Chat]', function () { messageWords.forEach((text) => { filterDiscussionsByText(text); }); - - it('should return an error when the messageId is invalid', (done) => { - request - .get(api('chat.getSnippetedMessageById?messageId=invalid-id')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(400) - .expect((res) => { - expect(res.body).to.have.property('success', false); - expect(res.body.error).to.be.equal('invalid-message'); - }) - .end(done); - }); }); }); diff --git a/packages/model-typings/src/models/IMessagesModel.ts b/packages/model-typings/src/models/IMessagesModel.ts index fed76010e137..d80f3757a3ff 100644 --- a/packages/model-typings/src/models/IMessagesModel.ts +++ b/packages/model-typings/src/models/IMessagesModel.ts @@ -18,8 +18,6 @@ export interface IMessagesModel extends IBaseModel { options?: FindOptions, ): FindPaginated>; - findSnippetedByRoom(roomId: IRoom['_id'], options: FindOptions): FindPaginated>; - findDiscussionsByRoom(rid: IRoom['_id'], options: FindOptions): FindCursor; findDiscussionsByRoomAndText(rid: IRoom['_id'], text: string, options: FindOptions): FindPaginated>; From e4a1e761961d90ce2a0ab59ab44ab43ec22b85f5 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 12:54:33 -0300 Subject: [PATCH 15/20] removed snippet page --- apps/meteor/client/startup/routes.tsx | 11 ----------- .../definition/externals/meteor/templating.d.ts | 2 -- 2 files changed, 13 deletions(-) diff --git a/apps/meteor/client/startup/routes.tsx b/apps/meteor/client/startup/routes.tsx index 9a12675ca871..334c787b7d55 100644 --- a/apps/meteor/client/startup/routes.tsx +++ b/apps/meteor/client/startup/routes.tsx @@ -235,17 +235,6 @@ FlowRouter.route('/reset-password/:token', { }, }); -FlowRouter.route('/snippet/:snippetId/:snippetName', { - name: 'snippetView', - action() { - appLayout.render( - - - , - ); - }, -}); - FlowRouter.route('/oauth/authorize', { name: 'oauth/authorize', action() { diff --git a/apps/meteor/definition/externals/meteor/templating.d.ts b/apps/meteor/definition/externals/meteor/templating.d.ts index 5ec2bb975589..2c62feb97668 100644 --- a/apps/meteor/definition/externals/meteor/templating.d.ts +++ b/apps/meteor/definition/externals/meteor/templating.d.ts @@ -38,8 +38,6 @@ declare module 'meteor/templating' { liveStreamBroadcast: Blaze.Template>; liveStreamTab: Blaze.Template>; liveStreamView: Blaze.Template>; - snippetPage: Blaze.Template>; - snippetedMessages: Blaze.Template>; inputAutocomplete: Blaze.Template>; textareaAutocomplete: Blaze.Template>; _autocompleteContainer: Blaze.Template>; From 3cfffdc0265be5f416d4b1b5d566937fb477d7d7 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 12:54:44 -0300 Subject: [PATCH 16/20] removed API_EmbedDisabledFor --- apps/meteor/app/lib/server/startup/settings.ts | 8 -------- apps/meteor/app/ui-message/client/message.js | 9 --------- apps/meteor/app/ui-utils/client/lib/messageContext.ts | 4 ---- .../views/room/components/body/useRoomMessageContext.ts | 3 --- apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json | 2 -- apps/meteor/server/startup/migrations/v287.ts | 1 + 6 files changed, 1 insertion(+), 26 deletions(-) diff --git a/apps/meteor/app/lib/server/startup/settings.ts b/apps/meteor/app/lib/server/startup/settings.ts index 0b96d43c62a5..fd302cd4f4ff 100644 --- a/apps/meteor/app/lib/server/startup/settings.ts +++ b/apps/meteor/app/lib/server/startup/settings.ts @@ -1291,14 +1291,6 @@ settingsRegistry.addGroup('Message', function () { public: true, }); - // TODO: deprecate this setting in favor of App - this.add('API_EmbedDisabledFor', '', { - type: 'string', - public: true, - i18nDescription: 'API_EmbedDisabledFor_Description', - alert: 'This_is_a_deprecated_feature_alert', - }); - // TODO: deprecate this setting in favor of App this.add('API_EmbedIgnoredHosts', 'localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16', { type: 'string', diff --git a/apps/meteor/app/ui-message/client/message.js b/apps/meteor/app/ui-message/client/message.js index 8946b33b2e87..38eed20870fb 100644 --- a/apps/meteor/app/ui-message/client/message.js +++ b/apps/meteor/app/ui-message/client/message.js @@ -309,15 +309,6 @@ Template.message.helpers({ return false; } - // check if oembed is disabled for message's sender - if ( - (settings.API_EmbedDisabledFor || '') - .split(',') - .map((username) => username.trim()) - .includes(msg.u && msg.u.username) - ) { - return false; - } return true; }, reactions() { diff --git a/apps/meteor/app/ui-utils/client/lib/messageContext.ts b/apps/meteor/app/ui-utils/client/lib/messageContext.ts index d243f0c9c599..14f519d7d348 100644 --- a/apps/meteor/app/ui-utils/client/lib/messageContext.ts +++ b/apps/meteor/app/ui-utils/client/lib/messageContext.ts @@ -70,8 +70,6 @@ export const createMessageContext = ({ // eslint-disable-next-line @typescript-eslint/naming-convention API_Embed = settings.get('API_Embed'), // eslint-disable-next-line @typescript-eslint/naming-convention - API_EmbedDisabledFor = settings.get('API_EmbedDisabledFor'), - // eslint-disable-next-line @typescript-eslint/naming-convention Message_GroupingPeriod = settings.get('Message_GroupingPeriod') * 1000, }: { uid?: IUser['_id'] | null; @@ -96,7 +94,6 @@ export const createMessageContext = ({ Message_AllowEditing?: unknown; Message_AllowEditing_BlockEditInMinutes?: unknown; API_Embed?: unknown; - API_EmbedDisabledFor?: unknown; Message_GroupingPeriod?: unknown; } = {}) => { return { @@ -119,7 +116,6 @@ export const createMessageContext = ({ Message_AllowEditing, Message_AllowEditing_BlockEditInMinutes, API_Embed, - API_EmbedDisabledFor, Message_GroupingPeriod, }, } as const; diff --git a/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts b/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts index 7c7b9ef457a2..77c7aba178be 100644 --- a/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts +++ b/apps/meteor/client/views/room/components/body/useRoomMessageContext.ts @@ -28,7 +28,6 @@ export const useRoomMessageContext = (room: IRoom) => { const allowEditing = useSetting('Message_AllowEditing'); const blockEditInMinutes = useSetting('Message_AllowEditing_BlockEditInMinutes'); const embed = useSetting('API_Embed'); - const embedDisabledFor = useSetting('API_EmbedDisabledFor'); const groupingPeriod = useSetting('Message_GroupingPeriod') as number; return useMemo( @@ -54,7 +53,6 @@ export const useRoomMessageContext = (room: IRoom) => { Message_AllowEditing: allowEditing, Message_AllowEditing_BlockEditInMinutes: blockEditInMinutes, API_Embed: embed, - API_EmbedDisabledFor: embedDisabledFor, Message_GroupingPeriod: groupingPeriod * 1000, }), [ @@ -66,7 +64,6 @@ export const useRoomMessageContext = (room: IRoom) => { collapseMediaByDefault, displayRoles, embed, - embedDisabledFor, groupingPeriod, hasPermissionDeleteMessage, hasPermissionDeleteOwnMessage, diff --git a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json index 8ee6354606d8..2df3747d641f 100644 --- a/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json @@ -399,8 +399,6 @@ "API_Drupal_URL_Description": "Example: https://domain.com (excluding trailing slash)", "API_Embed": "Embed Link Previews", "API_Embed_Description": "Whether embedded link previews are enabled or not when a user posts a link to a website.", - "API_EmbedDisabledFor": "Disable Embed for Users", - "API_EmbedDisabledFor_Description": "Comma-separated list of usernames to disable the embedded link previews.", "API_EmbedIgnoredHosts": "Embed Ignored Hosts", "API_EmbedIgnoredHosts_Description": "Comma-separated list of hosts or CIDR addresses, eg. localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16", "API_EmbedSafePorts": "Safe Ports", diff --git a/apps/meteor/server/startup/migrations/v287.ts b/apps/meteor/server/startup/migrations/v287.ts index c6f463370eaa..3a1ff7f2e6cb 100644 --- a/apps/meteor/server/startup/migrations/v287.ts +++ b/apps/meteor/server/startup/migrations/v287.ts @@ -31,6 +31,7 @@ addMigration({ 'AutoLinker_Phone', 'IssueLinks_Enabled', 'IssueLinks_Template', + 'API_EmbedDisabledFor', ]; Settings.deleteMany({ From a6ec44bb2453cb2f7ca644e594ba7864abd77cb5 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 12:56:37 -0300 Subject: [PATCH 17/20] move old embed settings line location --- .../meteor/app/lib/server/startup/settings.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/meteor/app/lib/server/startup/settings.ts b/apps/meteor/app/lib/server/startup/settings.ts index fd302cd4f4ff..e4ad85ee7048 100644 --- a/apps/meteor/app/lib/server/startup/settings.ts +++ b/apps/meteor/app/lib/server/startup/settings.ts @@ -1260,6 +1260,15 @@ settingsRegistry.addGroup('Message', function () { actionText: 'clear', i18nLabel: 'clear_cache_now', }); + // TODO: deprecate this setting in favor of App + this.add('API_EmbedIgnoredHosts', 'localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16', { + type: 'string', + i18nDescription: 'API_EmbedIgnoredHosts_Description', + }); + // TODO: deprecate this setting in favor of App + this.add('API_EmbedSafePorts', '80, 443', { + type: 'string', + }); this.add('Message_TimeFormat', 'LT', { type: 'string', public: true, @@ -1291,16 +1300,6 @@ settingsRegistry.addGroup('Message', function () { public: true, }); - // TODO: deprecate this setting in favor of App - this.add('API_EmbedIgnoredHosts', 'localhost, 127.0.0.1, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16', { - type: 'string', - i18nDescription: 'API_EmbedIgnoredHosts_Description', - }); - // TODO: deprecate this setting in favor of App - this.add('API_EmbedSafePorts', '80, 443', { - type: 'string', - }); - this.add('Message_ErasureType', 'Delete', { type: 'select', public: true, From 5d3447e93ca5374200f116c8799d2f632fb7dfb6 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 13:58:37 -0300 Subject: [PATCH 18/20] updated migration and removed unused variables --- .../views/admin/info/DeploymentCard.stories.tsx | 2 -- .../views/admin/info/InformationPage.stories.tsx | 2 -- .../client/views/admin/info/UsageCard.stories.tsx | 2 -- apps/meteor/server/startup/migrations/v287.ts | 15 ++++++++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/meteor/client/views/admin/info/DeploymentCard.stories.tsx b/apps/meteor/client/views/admin/info/DeploymentCard.stories.tsx index c591d9206049..f5aceed9634e 100644 --- a/apps/meteor/client/views/admin/info/DeploymentCard.stories.tsx +++ b/apps/meteor/client/views/admin/info/DeploymentCard.stories.tsx @@ -202,10 +202,8 @@ export default { customScript: 0, tabInvites: 0, totalEmailInvitation: 0, - totalRoomsWithSnippet: 0, totalRoomsWithStarred: 0, totalRoomsWithPinned: 0, - totalSnippet: 0, totalStarred: 0, totalPinned: 0, totalE2ERooms: 0, diff --git a/apps/meteor/client/views/admin/info/InformationPage.stories.tsx b/apps/meteor/client/views/admin/info/InformationPage.stories.tsx index b5c91798d5f4..cd0b6fa64c97 100644 --- a/apps/meteor/client/views/admin/info/InformationPage.stories.tsx +++ b/apps/meteor/client/views/admin/info/InformationPage.stories.tsx @@ -232,10 +232,8 @@ export default { customScript: 0, tabInvites: 0, totalEmailInvitation: 0, - totalRoomsWithSnippet: 0, totalRoomsWithStarred: 0, totalRoomsWithPinned: 0, - totalSnippet: 0, totalStarred: 0, totalPinned: 0, totalE2ERooms: 0, diff --git a/apps/meteor/client/views/admin/info/UsageCard.stories.tsx b/apps/meteor/client/views/admin/info/UsageCard.stories.tsx index 2081987efebc..081731e529cf 100644 --- a/apps/meteor/client/views/admin/info/UsageCard.stories.tsx +++ b/apps/meteor/client/views/admin/info/UsageCard.stories.tsx @@ -180,10 +180,8 @@ export default { customScript: 0, tabInvites: 0, totalEmailInvitation: 0, - totalRoomsWithSnippet: 0, totalRoomsWithStarred: 0, totalRoomsWithPinned: 0, - totalSnippet: 0, totalStarred: 0, totalPinned: 0, totalE2ERooms: 0, diff --git a/apps/meteor/server/startup/migrations/v287.ts b/apps/meteor/server/startup/migrations/v287.ts index 3a1ff7f2e6cb..f1497ab82f38 100644 --- a/apps/meteor/server/startup/migrations/v287.ts +++ b/apps/meteor/server/startup/migrations/v287.ts @@ -1,11 +1,12 @@ -import { Messages, Settings } from '@rocket.chat/models'; +import { Settings } from '@rocket.chat/models'; +import { MongoInternals } from 'meteor/mongo'; import { addMigration } from '../../lib/migrations'; import { upsertPermissions } from '../../../app/authorization/server/functions/upsertPermissions'; addMigration({ version: 287, - up() { + async up() { const deprecatedSettings = [ 'Markdown_Parser', 'Markdown_Headers', @@ -34,11 +35,14 @@ addMigration({ 'API_EmbedDisabledFor', ]; - Settings.deleteMany({ + await Settings.deleteMany({ _id: { $in: deprecatedSettings }, }); - Messages.updateMany( + const { mongo } = MongoInternals.defaultRemoteCollectionDriver(); + const messages = mongo.db.collection('rocketchat_message'); + + await messages.updateMany( { snippeted: true, }, @@ -51,7 +55,8 @@ addMigration({ }, }, ); + await messages.dropIndex('snippeted_1'); - upsertPermissions(); + await upsertPermissions(); }, }); From 34d1baba40bb2692e6509df9f784c792df3b05ed Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 14:05:43 -0300 Subject: [PATCH 19/20] removed marked parser and smaller updates --- apps/meteor/app/markdown/lib/markdown.js | 4 +- .../app/markdown/lib/parser/marked/marked.js | 106 ------------------ apps/meteor/app/markdown/server/index.js | 2 + 3 files changed, 4 insertions(+), 108 deletions(-) delete mode 100644 apps/meteor/app/markdown/lib/parser/marked/marked.js diff --git a/apps/meteor/app/markdown/lib/markdown.js b/apps/meteor/app/markdown/lib/markdown.js index a3a95e295dc8..8f0f34cadde6 100644 --- a/apps/meteor/app/markdown/lib/markdown.js +++ b/apps/meteor/app/markdown/lib/markdown.js @@ -5,14 +5,12 @@ import { Meteor } from 'meteor/meteor'; import { escapeHTML } from '@rocket.chat/string-helpers'; -import { marked } from './parser/marked/marked'; import { original } from './parser/original/original'; import { filtered } from './parser/filtered/filtered'; import { code } from './parser/original/code'; const parsers = { original, - marked, filtered, }; @@ -34,6 +32,8 @@ class MarkdownClass { parseMessageNotEscaped(message) { const options = { rootUrl: Meteor.absoluteUrl(), + supportSchemesForLink: 'http,https', + headers: false, }; return parsers.original(message, options); diff --git a/apps/meteor/app/markdown/lib/parser/marked/marked.js b/apps/meteor/app/markdown/lib/parser/marked/marked.js deleted file mode 100644 index a1aff30618c4..000000000000 --- a/apps/meteor/app/markdown/lib/parser/marked/marked.js +++ /dev/null @@ -1,106 +0,0 @@ -import { Random } from 'meteor/random'; -import _ from 'underscore'; -import { marked as _marked } from 'marked'; -import createDOMPurify from 'dompurify'; -import { unescapeHTML, escapeHTML } from '@rocket.chat/string-helpers'; - -import hljs, { register } from '../../hljs'; -import { getGlobalWindow } from '../../getGlobalWindow'; - -const renderer = new _marked.Renderer(); - -let msg = null; - -renderer.code = function (code, lang, escaped) { - if (this.options.highlight) { - const out = this.options.highlight(code, lang); - if (out != null && out !== code) { - escaped = true; - code = out; - } - } - - let text = null; - - if (!lang) { - text = `
    ${escaped ? code : escapeHTML(code)}
    `; - } else { - text = `
    ${escaped ? code : escapeHTML(code)}
    `; - } - - if (_.isString(msg)) { - return text; - } - - const token = `=!=${Random.id()}=!=`; - msg.tokens.push({ - highlight: true, - token, - text, - }); - - return token; -}; - -renderer.codespan = function (text) { - text = `${text}`; - if (_.isString(msg)) { - return text; - } - - const token = `=!=${Random.id()}=!=`; - msg.tokens.push({ - token, - text, - }); - - return token; -}; - -renderer.blockquote = function (quote) { - return `
    ${quote}
    `; -}; - -const linkRenderer = renderer.link; -renderer.link = function (href, title, text) { - const html = linkRenderer.call(renderer, href, title, text); - return html.replace(/^ { - msg = message; - - if (!message.tokens) { - message.tokens = []; - } - - message.html = _marked.parse(unescapeHTML(message.html), { - gfm, - tables, - breaks, - pedantic, - smartLists, - smartypants, - renderer, - highlight, - }); - - const window = getGlobalWindow(); - const DomPurify = createDOMPurify(window); - message.html = DomPurify.sanitize(message.html, { ADD_ATTR: ['target'], FORBID_ATTR: ['style'], FORBID_TAGS: ['style'] }); - - return message; -}; diff --git a/apps/meteor/app/markdown/server/index.js b/apps/meteor/app/markdown/server/index.js index 8cf4e3078e48..9b72cc5cec5f 100644 --- a/apps/meteor/app/markdown/server/index.js +++ b/apps/meteor/app/markdown/server/index.js @@ -10,6 +10,8 @@ Meteor.startup(() => { Tracker.autorun(() => { const options = { rootUrl: Meteor.absoluteUrl(), + supportSchemesForLink: 'http,https', + headers: false, }; const renderMessage = createMarkdownMessageRenderer(options); From 52e24a7eee3a55bca52c61a556bac96798d2b419 Mon Sep 17 00:00:00 2001 From: LucianoPierdona Date: Fri, 10 Feb 2023 14:24:59 -0300 Subject: [PATCH 20/20] removed not needed options --- apps/meteor/app/markdown/lib/markdown.js | 2 -- apps/meteor/app/markdown/server/index.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/apps/meteor/app/markdown/lib/markdown.js b/apps/meteor/app/markdown/lib/markdown.js index 8f0f34cadde6..8f55cf17635c 100644 --- a/apps/meteor/app/markdown/lib/markdown.js +++ b/apps/meteor/app/markdown/lib/markdown.js @@ -32,8 +32,6 @@ class MarkdownClass { parseMessageNotEscaped(message) { const options = { rootUrl: Meteor.absoluteUrl(), - supportSchemesForLink: 'http,https', - headers: false, }; return parsers.original(message, options); diff --git a/apps/meteor/app/markdown/server/index.js b/apps/meteor/app/markdown/server/index.js index 9b72cc5cec5f..8cf4e3078e48 100644 --- a/apps/meteor/app/markdown/server/index.js +++ b/apps/meteor/app/markdown/server/index.js @@ -10,8 +10,6 @@ Meteor.startup(() => { Tracker.autorun(() => { const options = { rootUrl: Meteor.absoluteUrl(), - supportSchemesForLink: 'http,https', - headers: false, }; const renderMessage = createMarkdownMessageRenderer(options);