Skip to content

Commit

Permalink
fix: thread order constant names + log date on threads
Browse files Browse the repository at this point in the history
  • Loading branch information
ahochsteger committed May 29, 2024
1 parent d1a1a08 commit cb6624c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/docs/reference/enum-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
4 changes: 2 additions & 2 deletions src/lib/config/ThreadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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.
*/
ID = "id",
/**
* Order by the subject of the first message in the thread.
*/
SUBJECT = "firstMessageSubject",
FIRST_MESSAGE_SUBJECT = "firstMessageSubject",
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/lib/processors/ThreadProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,21 @@ 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"])
})
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"])
Expand Down
6 changes: 3 additions & 3 deletions src/lib/processors/ThreadProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] *
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit cb6624c

Please sign in to comment.