From ec5bb4a4a8d9a50107695060dad54d0dee7a3084 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Sun, 5 Jan 2025 20:36:38 -0500 Subject: [PATCH] Generate color hashes for comment authors --- bun.lockb | Bin 31321 -> 32051 bytes package.json | 2 ++ src/threads/refresh.ts | 3 +++ src/types.ts | 1 + 4 files changed, 6 insertions(+) diff --git a/bun.lockb b/bun.lockb index 1248ee3bb58348f11b0a0f8d7516d3446964680b..fd715e2a9da11cf5d3236d4b6fccb8851badc98c 100755 GIT binary patch delta 4604 zcmd5mB_R+(5+Gl@B!-ZL1Ok<{ zVm9hn92te4vDQx-0Y9+f&>bAsRuOEeC>gP}6-H{u*3p*Y2U9HF%$W9f-g_&tqfY;5 zo!;4VfA`#T?m73Kd)~c!&t4MIVX@0KbJH(&zW(ar4+@UA&6>Kc_C)8A=5=H4>aMyr z=iq^y1An8Gy|+qwS+%=viab!Wds}w@c66jlQe?i6q!eHgPyue}YwhWV>@``EvcVq) zW&ulq>A>@2BqV0h(#aYA8Cd{1{9YA z*>C}nC$y!jbqnjZTMb9K=;sMeF)<6s6WFqO&RjOwyLDrDT~BLUirFs%c_FJ%v0isa zcUxX-NLmP<{ix_12aAzlUwGrX&W_<78MhsWunu=mH)j7fb0WMc#4 z4BXHc+NeA4*x1APGA!F6@9XXA*fLv^4uGEs{(c}wZve>Fdx0FCAP~Pu4Jw$9EC%x8 zi%oO`vFQHD3^dqr)SSQpAWyHWBeba(j)A;DY0&K71!M=!kny-sSFp2fL!Yz^Joo!C z8;)iK$PUZU&uGPLCjdR*;W9E!*Uyw94m8-%BrJ~|H`$}fW0uJ_-=~40yiHHNN%fXO zTTAA%+UC$uBki)R7k5+KqKRLUZ>%PUDU5m<#Zd30IO-GRvuetDY|?sI6I5#TifW2k zHL;K4s4tPvrils)+cae-a;ySc7CL72DrZd2s&m&OkCrB6Vk3nWO&q5f>Pr+?G$nhi zBo#w$C6VkE4HQn+Ec?*6kY2R7# zjwxPcFE}1+tnc@x43<*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T%3)24n3&@?AS6Ft?p%zsR((}*?U(TL;X)42dZEz>Fc&@Mo z&(XCOm;K59_4q>B|3@`iNbh)Ua*{sqs`l^=?9`fulNoOm=bPk8-ezc-l+@~4_+B3HXJB7}-rj~rw^gGThN4C?E_f<(asu*u5 zx=mh+Y+Fa0+OpE5Ep!e%mzR4(_9x8t8!Fca=!Lc|^ssGNAiX_re&EG{k7VHL&=L7h Dwo=vz 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 = {