Include extra notes in case summaries if there's space

This commit is contained in:
Dragory 2020-08-10 03:52:26 +03:00
parent b379bea9b8
commit d30cd0b764
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -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<CasesPluginType>,
@ -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) {