From d30cd0b7647be73c97aa63b93e7f778ad9260636 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Mon, 10 Aug 2020 03:52:26 +0300 Subject: [PATCH] Include extra notes in case summaries if there's space --- .../src/plugins/Cases/functions/getCaseSummary.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/src/plugins/Cases/functions/getCaseSummary.ts b/backend/src/plugins/Cases/functions/getCaseSummary.ts index 67e49322..4c1390ed 100644 --- a/backend/src/plugins/Cases/functions/getCaseSummary.ts +++ b/backend/src/plugins/Cases/functions/getCaseSummary.ts @@ -8,6 +8,8 @@ import { Case } from "../../../data/entities/Case"; import { inGuildTz } from "../../../utils/timezones"; const CASE_SUMMARY_REASON_MAX_LENGTH = 300; +const INCLUDE_MORE_NOTES_THRESHOLD = 20; +const UPDATED_STR = "__[Update]__"; export async function getCaseSummary( pluginData: PluginData, @@ -20,6 +22,13 @@ export async function getCaseSummary( const firstNote = theCase.notes[0]; let reason = firstNote ? firstNote.body : ""; + let leftoverNotes = Math.max(0, theCase.notes.length - 1); + + for (let i = 1; i < theCase.notes.length; i++) { + if (reason.length >= CASE_SUMMARY_REASON_MAX_LENGTH - UPDATED_STR.length - INCLUDE_MORE_NOTES_THRESHOLD) break; + reason += ` ${UPDATED_STR} ${theCase.notes[i].body}`; + leftoverNotes--; + } if (reason.length > CASE_SUMMARY_REASON_MAX_LENGTH) { const match = reason.slice(CASE_SUMMARY_REASON_MAX_LENGTH, 100).match(/(?:[.,!?\s]|$)/); @@ -44,8 +53,8 @@ export async function getCaseSummary( const caseType = `__${CaseTypes[theCase.type]}__`; let line = `\`[${prettyTimestamp}]\` ${caseTitle} ${caseType} ${reason}`; - if (theCase.notes.length > 1) { - line += ` *(+${theCase.notes.length - 1} ${theCase.notes.length === 2 ? "note" : "notes"})*`; + if (leftoverNotes > 1) { + line += ` *(+${leftoverNotes} ${leftoverNotes === 1 ? "note" : "notes"})*`; } if (theCase.is_hidden) {