Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions desktop/src/features/messages/lib/formatTimelineMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ import { truncatePubkey } from "@/shared/lib/pubkey";

const HEX_RE = /^[0-9a-f]+$/i;

function pubkeyToAccentColor(pubkey: string): string {
let hash = 0;
for (let i = 0; i < pubkey.length; i++) {
hash = (hash << 5) - hash + pubkey.charCodeAt(i);
hash |= 0;
}
const hue = Math.abs(hash) % 360;
return `hsla(${hue}, 65%, 55%, 0.10)`;
}

export function isTimelineContentEvent(event: RelayEvent) {
return (
event.kind === KIND_STREAM_MESSAGE ||
Expand Down Expand Up @@ -508,6 +518,7 @@ export function formatTimelineMessages(
rootId: thread.rootId,
depth: getDepth(event),
accent: currentPubkey === authorPubkey,
accentColor: authorPubkey ? pubkeyToAccentColor(authorPubkey) : undefined,
pending: event.pending,
edited: edit !== undefined,
kind: event.kind,
Expand Down
2 changes: 2 additions & 0 deletions desktop/src/features/messages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export type TimelineMessage = {
rootId?: string | null;
depth: number;
accent?: boolean;
/** Deterministic background tint derived from the sender's pubkey. */
accentColor?: string;
pending?: boolean;
edited?: boolean;
highlighted?: boolean;
Expand Down
8 changes: 8 additions & 0 deletions desktop/src/features/messages/ui/MessageRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,13 @@ export const MessageRow = React.memo(
data-testid="message-row"
onAnimationEnd={handleEntranceAnimationEnd}
>
{message.accentColor ? (
<div
aria-hidden
className="pointer-events-none absolute inset-0 -z-10 rounded-2xl"
style={{ backgroundColor: message.accentColor }}
/>
) : null}
{isThreadReplyLayout ? (
<>
{avatarGutterNode}
Expand Down Expand Up @@ -942,6 +949,7 @@ export const MessageRow = React.memo(
prev.message.ownerLabel === next.message.ownerLabel &&
prev.message.avatarUrl === next.message.avatarUrl &&
prev.message.accent === next.message.accent &&
prev.message.accentColor === next.message.accentColor &&
// The header timestamp and hover gutter both derive from createdAt (the
// old `time` prop was the same value pre-formatted; this row reads neither).
prev.message.createdAt === next.message.createdAt &&
Expand Down
Loading