feat: add IRC colours, without a toggle for now
Some checks failed
ci/woodpecker/push/build-and-publish Pipeline failed

This commit is contained in:
Twig 2025-07-13 18:16:02 +02:00
parent be5d65883b
commit 9b7de48c02
No known key found for this signature in database
4 changed files with 18 additions and 1 deletions

View file

@ -40,7 +40,7 @@
</div>
<div class="message-data">
<div class="message-metadata">
<span class="message-author-username" tabindex="0">
<span class="message-author-username" tabindex="0" :style="`color: ${props.authorColor}`">
{{ author?.display_name || author?.username }}
</span>
<span class="message-date" :title="date.toString()">
@ -71,6 +71,7 @@
import DOMPurify from 'dompurify';
import { parse } from 'marked';
import type { MessageProps } from '~/types/props';
import generateIrcColor from '~/utils/generateIrcColor';
const props = defineProps<MessageProps>();
@ -117,6 +118,8 @@ onMounted(async () => {
// showHover.value = !showHover.value;
//}
console.log(props.authorColor)
const menuItems = [
{ name: "Reply", callback: () => { if (messageElement.value) replyToMessage(messageElement.value, props) } }
]

View file

@ -7,6 +7,7 @@
:margin-bottom="(messages[i + 1] && messagesType[messages[i + 1].uuid] == 'normal') ?? false"
:last="i == messages.length - 1" :message-id="message.uuid" :author="message.user" :me="me"
:message="message" :is-reply="message.reply_to"
:author-color="`${generateIrcColor(message.user.uuid)}`"
:reply-message="message.reply_to ? getReplyMessage(message.reply_to) : undefined" />
</div>
<div id="message-box" class="rounded-corners">

View file

@ -9,6 +9,7 @@ export interface MessageProps {
format: "12" | "24",
type: "normal" | "grouped",
marginBottom: boolean,
authorColor: string,
last: boolean,
messageId: string,
replyingTo?: boolean,

12
utils/generateIrcColor.ts Normal file
View file

@ -0,0 +1,12 @@
import xxhash from "xxhash-wasm"
const { h64 } = await xxhash()
export default (seed: string): string => {
const lightness = 50
// this should probably be cached eventually
const idHash = h64(seed)
return `hsl(${idHash % 360n}, 100%, ${lightness}%)`
}