diff --git a/bun.lockb b/bun.lockb index 1248ee3..fd715e2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 19ed73a..5b1fbea 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,12 @@ "typescript": "^5.0.0" }, "dependencies": { + "@types/color-hash": "^2.0.0", "@types/imapflow": "^1.0.19", "@types/jsdom": "^21.1.7", "@types/mailparser": "^3.4.5", "blakejs": "^1.2.1", + "color-hash": "^2.0.2", "imapflow": "^1.0.171", "isomorphic-dompurify": "^2.19.0", "jsdom": "^25.0.1", diff --git a/src/threads/refresh.ts b/src/threads/refresh.ts index f5c23a5..3768588 100644 --- a/src/threads/refresh.ts +++ b/src/threads/refresh.ts @@ -7,6 +7,7 @@ import {config} from "../config.ts"; import { marked } from "marked"; import {sanitizeHtml} from "../mail/sanitize.ts"; import {formatThreadAddress} from "./id.ts"; +import ColorHash from "color-hash"; export async function refreshThreadsEntirely(): Promise { await withClient(async client => { @@ -46,6 +47,7 @@ export async function refreshThreadsEntirely(): Promise { // Pass 1: create all the ThreadComment instances and make a map by their ID const commentsByHash: {[hash: string]: ThreadComment} = {} const messages = messagesByThread[threadId] + const colorHash = new ColorHash(); for ( const message of messages ) { if ( !threadData.refresh.markers[message.mailbox] @@ -62,6 +64,7 @@ export async function refreshThreadsEntirely(): Promise { name: message.from.name || '(anonymous)', mailId: sha256(message.from.address!.toLowerCase()), domainId: sha256(message.from.address!.toLowerCase().split('@').reverse()[0]), + color: colorHash.hex(message.from.address!.toLowerCase()), }, date: message.date, subject: message.subject, diff --git a/src/types.ts b/src/types.ts index ef3f782..3dc28f4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,6 +51,7 @@ export type ThreadUser = { name: string, mailId: string, domainId: string, + color: string, } export type ThreadComment = {