fix: Quotes chain off by one error in quote chain limit settings (#28281)

Co-authored-by: Hugo Costa <20212776+hugocostadev@users.noreply.github.com>
pull/28770/head^2
Jayesh Jain 3 years ago committed by GitHub
parent 5bc44f3d4f
commit 39fcce55e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      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<number>('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<number>('Message_QuoteChainLimit');
if ((message.attachments && quoteChainLimit < 2) || isNaN(quoteChainLimit)) {
delete message.attachments;
}
message.attachments = message.attachments?.map((attachment) => recursiveRemoveAttachments(attachment, 1, quoteChainLimit));
return message;
};

Loading…
Cancel
Save