From cb6624c1f8c8cc620b5ffc7cd27a3c954399cddd Mon Sep 17 00:00:00 2001 From: Andreas Hochsteger Date: Wed, 29 May 2024 04:56:11 +0000 Subject: [PATCH] fix: thread order constant names + log date on threads --- docs/docs/reference/enum-types.mdx | 4 ++-- src/lib/config/ThreadConfig.ts | 4 ++-- src/lib/processors/ThreadProcessor.spec.ts | 10 ++++++++-- src/lib/processors/ThreadProcessor.ts | 6 +++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/docs/reference/enum-types.mdx b/docs/docs/reference/enum-types.mdx index e55fafce..c574a89f 100644 --- a/docs/docs/reference/enum-types.mdx +++ b/docs/docs/reference/enum-types.mdx @@ -185,6 +185,6 @@ Represents a thread field to be ordered by for processing. | Key | Value | Description | |-----|-------|-------------| -| `DATE` | `lastMessageDate` | Order by the date of the last message in the thread. | +| `FIRST_MESSAGE_SUBJECT` | `firstMessageSubject` | Order by the subject of the first message in the thread. | | `ID` | `id` | Order by the ID of the thread. | -| `SUBJECT` | `firstMessageSubject` | Order by the subject of the first message in the thread. | +| `LAST_MESSAGE_DATE` | `lastMessageDate` | Order by the date of the last message in the thread. | diff --git a/src/lib/config/ThreadConfig.ts b/src/lib/config/ThreadConfig.ts index 1a786dd8..6db65401 100644 --- a/src/lib/config/ThreadConfig.ts +++ b/src/lib/config/ThreadConfig.ts @@ -27,7 +27,7 @@ export enum ThreadOrderField { /** * Order by the date of the last message in the thread. */ - DATE = "lastMessageDate", + LAST_MESSAGE_DATE = "lastMessageDate", /** * Order by the ID of the thread. */ @@ -35,7 +35,7 @@ export enum ThreadOrderField { /** * Order by the subject of the first message in the thread. */ - SUBJECT = "firstMessageSubject", + FIRST_MESSAGE_SUBJECT = "firstMessageSubject", } /** diff --git a/src/lib/processors/ThreadProcessor.spec.ts b/src/lib/processors/ThreadProcessor.spec.ts index 16e0d021..c23e3eaf 100644 --- a/src/lib/processors/ThreadProcessor.spec.ts +++ b/src/lib/processors/ThreadProcessor.spec.ts @@ -133,7 +133,10 @@ describe("order threads", () => { it("should order threads ascending", () => { threads = ThreadProcessor.ordered( threads, - { orderBy: ThreadOrderField.DATE, orderDirection: OrderDirection.ASC }, + { + orderBy: ThreadOrderField.LAST_MESSAGE_DATE, + orderDirection: OrderDirection.ASC, + }, ThreadProcessor.orderRules, ) expect(threads.map((t) => t.getId())).toEqual(["t2", "t1", "t3"]) @@ -141,7 +144,10 @@ describe("order threads", () => { it("should order threads ascending", () => { threads = ThreadProcessor.ordered( threads, - { orderBy: ThreadOrderField.DATE, orderDirection: OrderDirection.DESC }, + { + orderBy: ThreadOrderField.LAST_MESSAGE_DATE, + orderDirection: OrderDirection.DESC, + }, ThreadProcessor.orderRules, ) expect(threads.map((t) => t.getId())).toEqual(["t3", "t1", "t2"]) diff --git a/src/lib/processors/ThreadProcessor.ts b/src/lib/processors/ThreadProcessor.ts index 7b4f1ee7..3927ef6a 100644 --- a/src/lib/processors/ThreadProcessor.ts +++ b/src/lib/processors/ThreadProcessor.ts @@ -359,10 +359,10 @@ export class ThreadProcessor extends BaseProcessor { ): number { return ( { - [ThreadOrderField.DATE]: + [ThreadOrderField.LAST_MESSAGE_DATE]: a.getLastMessageDate().getTime() - b.getLastMessageDate().getTime(), [ThreadOrderField.ID]: a.getId().localeCompare(b.getId()), - [ThreadOrderField.SUBJECT]: a + [ThreadOrderField.FIRST_MESSAGE_SUBJECT]: a .getFirstMessageSubject() .localeCompare(b.getFirstMessageSubject()), }[config.orderBy] * @@ -433,7 +433,7 @@ export class ThreadProcessor extends BaseProcessor { const config: RequiredThreadConfig = ctx.thread.config ctx.log.trace(ctx, { location: "ThreadProcessor.processEntity()", - message: `Processing thread id '${ctx.log.redact(ctx, thread.getId())}' (subject:'${ctx.log.redact(ctx, thread.getFirstMessageSubject())}') started ...`, + message: `Processing thread id '${ctx.log.redact(ctx, thread.getId())}' (lastMessageDate:${thread.getLastMessageDate().toISOString()}, subject:'${ctx.log.redact(ctx, thread.getFirstMessageSubject())}') started ...`, }) // Execute pre-main actions: result = this.executeActions(