Generate color hashes for comment authors

This commit is contained in:
2025-01-05 20:36:38 -05:00
parent 1f5889dc39
commit ec5bb4a4a8
4 changed files with 6 additions and 0 deletions

View File

@@ -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<void> {
await withClient(async client => {
@@ -46,6 +47,7 @@ export async function refreshThreadsEntirely(): Promise<void> {
// 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<void> {
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,

View File

@@ -51,6 +51,7 @@ export type ThreadUser = {
name: string,
mailId: string,
domainId: string,
color: string,
}
export type ThreadComment = {