From 5ffc3e7cc4e0970af140b9b1251e3c5c71ced8ef Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 13 Feb 2021 22:59:48 +0200 Subject: [PATCH] Fix formatting error in !cases with long code blocks --- backend/src/plugins/Cases/functions/getCaseSummary.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/Cases/functions/getCaseSummary.ts b/backend/src/plugins/Cases/functions/getCaseSummary.ts index a1395f63..d948fdac 100644 --- a/backend/src/plugins/Cases/functions/getCaseSummary.ts +++ b/backend/src/plugins/Cases/functions/getCaseSummary.ts @@ -16,6 +16,7 @@ import { humanizeDurationShort } from "../../../humanizeDurationShort"; import { caseAbbreviations } from "../caseAbbreviations"; import { getCaseIcon } from "./getCaseIcon"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; +import { splitIntoCleanChunks, splitMessageIntoChunks } from "knub/dist/helpers"; const CASE_SUMMARY_REASON_MAX_LENGTH = 300; const INCLUDE_MORE_NOTES_THRESHOLD = 20; @@ -49,9 +50,8 @@ export async function getCaseSummary( if (reason.length > CASE_SUMMARY_REASON_MAX_LENGTH) { const match = reason.slice(CASE_SUMMARY_REASON_MAX_LENGTH, 100).match(/(?:[.,!?\s]|$)/); const nextWhitespaceIndex = match ? CASE_SUMMARY_REASON_MAX_LENGTH + match.index! : CASE_SUMMARY_REASON_MAX_LENGTH; - if (nextWhitespaceIndex < reason.length) { - reason = reason.slice(0, nextWhitespaceIndex - 1) + "..."; - } + const reasonChunks = splitMessageIntoChunks(reason, nextWhitespaceIndex); + reason = reasonChunks[0] + "..."; } reason = disableLinkPreviews(reason);