From 39fcce55e630a66ced643b66b6345205ecf9e67a Mon Sep 17 00:00:00 2001 From: Jayesh Jain <79307894+jayesh-jain252@users.noreply.github.com> Date: Tue, 4 Apr 2023 20:56:17 +0530 Subject: [PATCH] fix: Quotes chain off by one error in quote chain limit settings (#28281) Co-authored-by: Hugo Costa <20212776+hugocostadev@users.noreply.github.com> --- apps/meteor/app/oembed/server/jumpToMessage.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/meteor/app/oembed/server/jumpToMessage.ts b/apps/meteor/app/oembed/server/jumpToMessage.ts index d36f5c21348..b48ea8907e1 100644 --- a/apps/meteor/app/oembed/server/jumpToMessage.ts +++ b/apps/meteor/app/oembed/server/jumpToMessage.ts @@ -11,10 +11,10 @@ import { settings } from '../../settings/server'; import { callbacks } from '../../../lib/callbacks'; import { canAccessRoomAsync } from '../../authorization/server/functions/canAccessRoom'; -const recursiveRemove = (attachments: MessageAttachment, deep = 1): MessageAttachment => { +const recursiveRemoveAttachments = (attachments: MessageAttachment, deep = 1, quoteChainLimit: number): MessageAttachment => { if (attachments && isQuoteAttachment(attachments)) { - if (deep < settings.get('Message_QuoteChainLimit')) { - attachments.attachments?.map((msg) => recursiveRemove(msg, deep + 1)); + if (deep < quoteChainLimit - 1) { + attachments.attachments?.map((msg) => recursiveRemoveAttachments(msg, deep + 1, quoteChainLimit)); } else { delete attachments.attachments; } @@ -28,7 +28,12 @@ const validateAttachmentDeepness = (message: IMessage): IMessage => { return message; } - message.attachments = message.attachments?.map((attachment) => recursiveRemove(attachment)); + const quoteChainLimit = settings.get('Message_QuoteChainLimit'); + if ((message.attachments && quoteChainLimit < 2) || isNaN(quoteChainLimit)) { + delete message.attachments; + } + + message.attachments = message.attachments?.map((attachment) => recursiveRemoveAttachments(attachment, 1, quoteChainLimit)); return message; };