Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): unify message author and timestamp layout (#999)

Gener00487d91fadf
diff --git a/src/web/src/components/community/messages/message-author-line.dom.test.tsx b/src/web/src/components/community/messages/message-author-line.dom.test.tsx
new file mode 100644
index 000000000..00b65c16f
--- /dev/null
+++ b/src/web/src/components/community/messages/message-author-line.dom.test.tsx
@@ -0,0 +1,56 @@
+import React from "react"
+import { describe, expect, it, vi } from "vitest"
+import { fireEvent, render } from "@/test/react-dom-harness"
+import { MessageAuthorLine } from "./message-author-line"
+
+describe("MessageAuthorLine", () => {
+ it.each(["Alice", "A long author name with spaces", "这是一个很长的中文姓名", "LongUnbrokenAuthorName".repeat(8)])(
+ "keeps the full accessible author name and forwards the click for %s",
+ (authorName) => {
+ const onAuthorClick = vi.fn()
+ const renderer = render(<MessageAuthorLine
+ authorName={authorName}
+ timestamp="12:34"
+ onAuthorClick={onAuthorClick}
+ color="var(--foreground)"
+ />)
+ const author = renderer.getByRole("button", { name: authorName })
+ expect(author).toHaveAttribute("title", authorName)
+ expect(author).toHaveTextContent(authorName)
+ expect(author.style.color).toBe("var(--foreground)")
+ fireEvent.click(author)
+ expect(onAuthorClick).toHaveBeenCalledOnce()
+ expect(onAuthorClick.mock.calls[0][0].target).toBe(author)
+ },
+ )
+
+ it.each(["compact", "note"] as const)("keeps a %s preview inside its original jump button", (variant) => {
+ const jump = vi.fn()
+ const renderer = render(<button type="button" onClick={jump}>
+ <MessageAuthorLine authorName="Alice" timestamp="2m" variant={variant} />
+ </button>)
+ expect(renderer.container.querySelectorAll("button")).toHaveLength(1)
+ fireEvent.click(renderer.getByTitle("Alice"))
+ expect(jump).toHaveBeenCalledOnce()
+ })
+
+ it("keeps static capture text and timestamp metadata on the actual time node", () => {
+ const dateTime = "2026-10-16T05:00:00.000Z"
+ const renderer = render(<MessageAuthorLine
+ authorName="Share author"
+ timestamp="13:00"
+ timestampProps={{ dateTime, "data-share-timestamp": true }}
+ />)
+ expect(renderer.queryByRole("button")).toBeNull()
+ const time = renderer.container.querySelector("time[data-share-timestamp]")!
+ expect(time).toHaveAttribute("datetime", dateTime)
+ expect(time).toHaveTextContent("13:00")
+ expect(time.previousElementSibling).toHaveAttribute("title", "Share author")
+ })
+
+ it("omits an absent timestamp without adding an empty time element", () => {
+ const renderer = render(<MessageAuthorLine authorName="Deleted user" />)
+ expect(renderer.container.querySelector("time")).toBeNull()
+ expect(renderer.getByTitle("Deleted user")).toHaveTextContent("Deleted user")
+ })
+})
diff --git a/src/web/src/components/community/messages/message-author-line.tsx b/src/web/src/components/community/messages/message-author-line.tsx
new file mode 100644
index 000000000..558c6279a
--- /dev/null
+++ b/src/web/src/components/community/messages/message-author-line.tsx
@@ -0,0 +1,78 @@
+import type { ComponentPropsWithoutRef, CSSProperties, MouseEventHandler, ReactNode } from "react"
+import { cn } from "@/lib/utils"
+
+type TimestampProps = Omit<ComponentPropsWithoutRef<"time">, "children" | "className"> & {
+ [attribute: `data-${string}`]: string | number | boolean | undefined
+}
+
+type MessageAuthorLineProps = {
+ authorName: string
+ timestamp?: ReactNode
+ timestampProps?: TimestampProps
+ onAuthorClick?: MouseEventHandler<HTMLButtonElement>
+ color?: CSSProperties["color"]
+ variant?: "message" | "compact" | "note"
+ className?: string
+}
+
+const typography = {
+ message: {
+ author: "text-[15px] font-semibold",
+ timestamp: "text-xs text-muted-foreground",
+ },
+ compact: {
+ author: "text-sm font-medium",
+ timestamp: "text-xs text-muted-foreground",
+ },
+ note: {
+ author: "font-semibold",
+ timestamp: "font-mono text-[9px] tabular-nums text-(--note-muted)",
+ },
+}
+
+export function MessageAuthorLine({
+ authorName,
+ timestamp,
+ timestampProps,
+ onAuthorClick,
+ color,
+ variant = "message",
+ className,
+}: MessageAuthorLineProps) {
+ const authorClassName = cn("min-w-0 max-w-full truncate", typography[variant].author)
+ return (
+ <div
+ data-message-author-line
+ className={cn(
+ "flex min-w-0 max-w-full items-baseline gap-2",
+ variant === "note" && "w-fit items-center text-xs leading-4",
+ className,
+ )}
+ >
+ {onAuthorClick ? (
+ <button
+ type="button"
+ onClick={onAuthorClick}
+ title={authorName}
+ className={cn(authorClassName, "hover:underline")}
+ style={{ color }}
+ >
+ {authorName}
+ </button>
+ ) : (
+ <span title={authorName} className={authorClassName} style={{ color }}>
+ {authorName}
+ </span>
+ )}
+ {timestamp != null && (
+ <time
+ {...timestampProps}
+ className={cn("shrink-0 whitespace-nowrap", typography[variant].timestamp)}
+ suppressHydrationWarning
+ >
+ {timestamp}
+ </time>
+ )}
+ </div>
+ )
+}
diff --git a/src/web/src/components/community/messages/message-share-dialog.dom.test.ts b/src/web/src/components/community/messages/message-share-dialog.dom.test.ts
index 298e28550..7d152b297 100644
--- a/src/web/src/components/community/messages/message-share-dialog.dom.test.ts
+++ b/src/web/src/components/community/messages/message-share-dialog.dom.test.ts
@@ -318,6 +318,9 @@ describe("MessageShareDialog message projection", () => {
expect(timestamp.classList).toContain("text-muted-foreground")
expect(timestamp.parentElement?.classList).toContain("items-baseline")
expect(timestamp.parentElement?.classList).toContain("gap-2")
+ expect(timestamp).toHaveAttribute("datetime", createdAt)
+ expect(timestamp.parentElement?.querySelector("button")).toBeNull()
+ expect(timestamp.previousElementSibling).toHaveAttribute("title", "Alice")
})
it("keeps the author and timestamp collapsed for grouped follow-ups", async () => {
diff --git a/src/web/src/components/community/messages/message-share-dialog.tsx b/src/web/src/components/community/messages/message-share-dialog.tsx
index 846bf2cef..9942e8cee 100644
--- a/src/web/src/components/community/messages/message-share-dialog.tsx
+++ b/src/web/src/components/community/messages/message-share-dialog.tsx
@@ -16,6 +16,7 @@ import { Button } from "@/components/ui/button"
import { Avatar } from "../avatar"
import { ShareImagePreparationContext } from "@/components/remote-image/share-image-context"
import { MessageBody } from "./message-body"
+import { MessageAuthorLine } from "./message-author-line"
import { attachmentAspectRatio } from "./attachment-layout"
import { tid } from "@/lib/community/testids"
import { applyHighlightToRange, clearHighlights, hasHighlights } from "@/lib/community/highlight-range"
@@ -348,23 +349,13 @@ export function MessageShareDialog({ m, open, onClose }: {
)}
<div className="min-w-0 flex-1">
{!msg.grouped && (
- <div
- className="mb-0.5 flex items-baseline gap-2"
- >
- <span
- className="min-w-0 max-w-full truncate text-[15px] font-semibold"
- style={{ color: msg.color ?? "var(--foreground)" }}
- >
- {author?.name ?? msg.authorName}
- </span>
- <span
- data-share-timestamp
- className="shrink-0 text-xs text-muted-foreground"
- suppressHydrationWarning
- >
- {formatMessageTime(msg.createdAt)}
- </span>
- </div>
+ <MessageAuthorLine
+ className="mb-0.5"
+ authorName={author?.name ?? msg.authorName ?? ""}
+ color={msg.color ?? "var(--foreground)"}
+ timestamp={formatMessageTime(msg.createdAt)}
+ timestampProps={{ dateTime: msg.createdAt, "data-share-timestamp": true }}
+ />
)}
{visibleContent && (
<div
diff --git a/src/web/src/components/community/messages/message.render.dom.test.ts b/src/web/src/components/community/messages/message.render.dom.test.ts
index c0ca91a7d..1f9babead 100644
--- a/src/web/src/components/community/messages/message.render.dom.test.ts
+++ b/src/web/src/components/community/messages/message.render.dom.test.ts
@@ -356,6 +356,22 @@ afterEach(() => {
vi.unstubAllGlobals()
})
+describe("Message author line", () => {
+ it.each([false, true])("keeps selection local while grouped is %s", (grouped) => {
+ const onToggleSelect = vi.fn()
+ const view = rtlRender(makeTree({
+ m: baseMsg({ grouped }),
+ selectMode: true,
+ selected: true,
+ onToggleSelect,
+ }))
+ expect(view.container.querySelectorAll("[data-message-author-line]")).toHaveLength(grouped ? 0 : 1)
+ expect(view.container.querySelectorAll("[data-message-selection-checkbox]")).toHaveLength(1)
+ fireEvent.click(view.getByText("hello"))
+ expect(onToggleSelect).toHaveBeenCalledOnce()
+ })
+})
+
describe("Message memo comparator", () => {
it.each([true, false])("selects an external-link message without navigating (hover: %s)", async (hoverCapable) => {
const onToggleSelect = vi.fn()
diff --git a/src/web/src/components/community/messages/message.tsx b/src/web/src/components/community/messages/message.tsx
index b4835dcd9..b3ce5af1b 100644
--- a/src/web/src/components/community/messages/message.tsx
+++ b/src/web/src/components/community/messages/message.tsx
@@ -12,6 +12,7 @@ import { ContextMenu, ContextMenuTrigger, ContextMenuContent } from "@/component
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent } from "@/components/ui/dropdown-menu"
import { Avatar } from "../avatar"
import { MessageBody } from "./message-body"
+import { MessageAuthorLine } from "./message-author-line"
import {
copyMessageExternalLink,
messageExternalLinkTargetFromEventTarget,
@@ -666,14 +667,13 @@ function MessageImpl({
)}
{!m.grouped && (
<div className={`relative flex items-baseline gap-2${selectable ? " pr-6" : ""}`}>
- <button
- onClick={(e) => onOpenProfile?.(authorName, e, undefined, m.authorId)}
- className="min-w-0 max-w-full truncate text-[15px] font-semibold hover:underline"
- style={{ color: m.color ?? "var(--foreground)" }}
- >
- {authorName}
- </button>
- <span className="shrink-0 text-xs text-muted-foreground" suppressHydrationWarning>{formatMessageTime(m.createdAt)}</span>
+ <MessageAuthorLine
+ authorName={authorName}
+ onAuthorClick={(e) => onOpenProfile?.(authorName, e, undefined, m.authorId)}
+ color={m.color ?? "var(--foreground)"}
+ timestamp={formatMessageTime(m.createdAt)}
+ timestampProps={{ dateTime: m.createdAt }}
+ />
{selectable && (
<span
aria-hidden
diff --git a/src/web/src/components/community/messages/thread-opener.dom.test.ts b/src/web/src/components/community/messages/thread-opener.dom.test.ts
index f44923864..3cdef786e 100644
--- a/src/web/src/components/community/messages/thread-opener.dom.test.ts
+++ b/src/web/src/components/community/messages/thread-opener.dom.test.ts
@@ -4,12 +4,13 @@ import { act, fireEvent } from "@/test/react-dom-harness"
import { renderCommunity as render } from "@/test/community-owner-harness"
const useMessageMock = vi.fn()
+const profileState = vi.hoisted(() => ({ name: "Alice" }))
vi.mock("@/hooks/community/use-message", () => ({
useMessage: (...args: unknown[]) => useMessageMock(...args),
}))
vi.mock("@/lib/community-db/projections", async (importOriginal) => ({ ...await importOriginal<typeof import("@/lib/community-db/projections")>(),
useCanonicalCommunityProfile: (userId?: string) => userId
- ? { id: userId, name: "Alice", avatar: "A" }
+ ? { id: userId, name: profileState.name, avatar: "A" }
: undefined,
}))
vi.mock("@/hooks/use-hover-capable", () => ({ useHoverCapable: () => true }))
@@ -26,10 +27,45 @@ import { attachmentImageFrameStyle } from "./attachment-layout"
describe("ThreadOpener image attachment layout", () => {
afterEach(() => {
+ profileState.name = "Alice"
vi.useRealTimers()
vi.unstubAllGlobals()
})
+ it("keeps the full canonical author, exact profile target and original Jump action", () => {
+ const authorName = "这是很长的作者姓名 LongUnbrokenName".repeat(4)
+ const createdAt = "2026-08-08T00:00:00.000Z"
+ profileState.name = authorName
+ useMessageMock.mockReturnValue({
+ isLoading: false,
+ isError: false,
+ message: {
+ id: "opener_1", type: "chat", authorId: "user_1",
+ authorName: "Stale name", createdAt, content: "Original body",
+ },
+ })
+ const onOpenProfile = vi.fn()
+ const onJump = vi.fn()
+ const renderer = render(React.createElement(ThreadOpener, {
+ parentMessageId: "opener_1", parentChannelId: "parent_1", serverId: "server_1",
+ viewerUserId: "viewer_1", onOpenProfile, onJump,
+ }))
+ const author = renderer.getByRole("button", { name: authorName })
+ expect(author).toHaveAttribute("title", authorName)
+ expect(renderer.queryByText("Stale name")).toBeNull()
+ expect(renderer.container.querySelector("[data-message-author-line] time"))
+ .toHaveAttribute("datetime", createdAt)
+ fireEvent.click(author)
+ expect(onOpenProfile).toHaveBeenCalledExactlyOnceWith(
+ authorName, expect.objectContaining({ target: author }), undefined, "user_1",
+ )
+ expect(renderer.getByText("Thread started from")).toBeInTheDocument()
+ expect(renderer.getByText("Original body")).toBeInTheDocument()
+ fireEvent.click(renderer.getByRole("button", { name: "Jump to message" }))
+ expect(onJump).toHaveBeenCalledOnce()
+ expect(onOpenProfile).toHaveBeenCalledOnce()
+ })
+
it.each(["attachment", "Markdown"])("retires a previous opener's $name attempt even when its source is reused", async (kind) => {
const select = (id: string) => useMessageMock.mockReturnValue({
isLoading: false,
diff --git a/src/web/src/components/community/messages/thread-opener.tsx b/src/web/src/components/community/messages/thread-opener.tsx
index 5b77dca03..6de9fdb93 100644
--- a/src/web/src/components/community/messages/thread-opener.tsx
+++ b/src/web/src/components/community/messages/thread-opener.tsx
@@ -3,6 +3,7 @@
import { MessagesSquare, ArrowUpRight } from "lucide-react"
import { Avatar } from "../avatar"
import { MessageBody } from "./message-body"
+import { MessageAuthorLine } from "./message-author-line"
import { attachmentImageFrameStyle } from "./attachment-layout"
import { formatMessageTime } from "@/lib/community/format-time"
import { Skeleton } from "@/components/ui/skeleton"
@@ -27,11 +28,6 @@ import { RemoteContentImage } from "@/components/remote-image/remote-image"
// plain caption above it is enough to mark it as context, not part of the
// thread's own reply timeline.
//
-// The parent lives in the OUTER channel — since server membership grants
-// channel access, any thread viewer can fetch it via the shared endpoint.
-// Fetching client-side (rather than embedding in the channels/[id] response)
-// keeps the parent live: an edit or reaction on the source message would
-// reflect here without a page reload once the mutation invalidates this key.
export function ThreadOpener({
parentMessageId,
parentChannelId,
@@ -138,17 +134,12 @@ export function ThreadOpener({
<Avatar label={avatarLabel} seed={msg.authorId} size={40} />
</button>
<div className="flex min-w-0 flex-1 flex-col gap-2">
- <div className="flex items-baseline gap-2">
- <button
- onClick={(e) => onOpenProfile?.(authorName, e, undefined, msg.authorId)}
- className="text-[15px] font-semibold hover:underline"
- >
- {authorName}
- </button>
- <span className="text-xs text-muted-foreground" suppressHydrationWarning>
- {formatMessageTime(msg.createdAt)}
- </span>
- </div>
+ <MessageAuthorLine
+ authorName={authorName}
+ onAuthorClick={(e) => onOpenProfile?.(authorName, e, undefined, msg.authorId)}
+ timestamp={formatMessageTime(msg.createdAt)}
+ timestampProps={{ dateTime: msg.createdAt }}
+ />
{visibleContent && (
<MessageBody
diff --git a/src/web/src/components/community/shell/community-panel.dom.test.tsx b/src/web/src/components/community/shell/community-panel.dom.test.tsx
new file mode 100644
index 000000000..f2eec03f2
--- /dev/null
+++ b/src/web/src/components/community/shell/community-panel.dom.test.tsx
@@ -0,0 +1,46 @@
+import React from "react"
+import { describe, expect, it, vi } from "vitest"
+import { fireEvent } from "@/test/react-dom-harness"
+import { renderCommunity as render } from "@/test/community-owner-harness"
+
+vi.mock("./community-sheet", () => ({
+ CommunitySheet: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
+}))
+vi.mock("@/lib/community-db/projections", async (importOriginal) => ({
+ ...await importOriginal<typeof import("@/lib/community-db/projections")>(),
+ useCanonicalProfilesByUserId: () => new Map([
+ ["user_1", { id: "user_1", name: "Canonical long author name", avatar: "A" }],
+ ]),
+}))
+
+import { CommunityPanel } from "./community-panel"
+
+describe("CommunityPanel pinned author line", () => {
+ it("uses the canonical author and keeps the exact message jump on one outer button", () => {
+ const onJumpToMessage = vi.fn()
+ const createdAt = "2026-10-16T05:00:00.000Z"
+ const view = render(<CommunityPanel
+ open
+ onOpenChange={vi.fn()}
+ kind="pinned"
+ members={[]}
+ pinned={[{
+ id: "message_1", type: "chat", seq: 42,
+ authorId: "user_1", authorName: "Stale author",
+ content: "Pinned body", createdAt,
+ }]}
+ searchResults={[]}
+ threads={[]}
+ onOpenThread={vi.fn()}
+ onJumpToMessage={onJumpToMessage}
+ />)
+ const author = view.getByTitle("Canonical long author name")
+ const row = author.closest("button")!
+ expect(view.queryByText("Stale author")).toBeNull()
+ expect(row.querySelectorAll("button")).toHaveLength(0)
+ expect(row.querySelector("time")).toHaveAttribute("datetime", createdAt)
+ expect(row).toHaveTextContent("Pinned body")
+ fireEvent.click(author)
+ expect(onJumpToMessage).toHaveBeenCalledExactlyOnceWith(42)
+ })
+})
diff --git a/src/web/src/components/community/shell/community-panel.tsx b/src/web/src/components/community/shell/community-panel.tsx
index ab9e3147f..4383c67b7 100644
--- a/src/web/src/components/community/shell/community-panel.tsx
+++ b/src/web/src/components/community/shell/community-panel.tsx
@@ -8,6 +8,7 @@ import { stripInlineMarkup, type CommunityRole as Role } from "@alook/shared"
import { Avatar } from "@/components/community/avatar"
import { MemberList } from "@/components/community/members/member-list"
import { Message } from "@/components/community/messages/message"
+import { MessageAuthorLine } from "@/components/community/messages/message-author-line"
import { CommunitySheet } from "@/components/community/shell/community-sheet"
import { Input } from "@/components/ui/input"
import { Skeleton } from "@/components/ui/skeleton"
@@ -145,14 +146,12 @@ function renderCommunityPanelBody({
<Avatar label={author.avatar} seed={message.authorId} size={24} />
</span>
<div className="min-w-0 flex-1">
- <div className="flex items-baseline gap-2">
- <span className="text-sm font-medium">{author.name}</span>
- {message.createdAt && (
- <span className="text-xs text-muted-foreground">
- {formatRelativeTime(message.createdAt)}
- </span>
- )}
- </div>
+ <MessageAuthorLine
+ variant="compact"
+ authorName={author.name}
+ timestamp={message.createdAt ? formatRelativeTime(message.createdAt) : undefined}
+ timestampProps={{ dateTime: message.createdAt }}
+ />
<div className="truncate text-sm text-muted-foreground">
{stripInlineMarkup(message.content ?? "")}
</div>
diff --git a/src/web/src/components/community/social/bot-mark-sticker.dom.test.ts b/src/web/src/components/community/social/bot-mark-sticker.dom.test.ts
index 19f6c1d10..6082bebe0 100644
--- a/src/web/src/components/community/social/bot-mark-sticker.dom.test.ts
+++ b/src/web/src/components/community/social/bot-mark-sticker.dom.test.ts
@@ -356,6 +356,10 @@ describe("BotMarkSticker", () => {
expect(renderer.container.textContent).toContain("First")
expect(renderer.container.textContent).not.toContain("**First**")
expect(renderer.container.textContent).toContain("Gus")
+ const authorLine = rows[0]!.querySelector("[data-message-author-line]")!
+ expect(authorLine.querySelector("button")).toBeNull()
+ expect(authorLine.querySelector('[title="Gus"]')).toHaveTextContent("Gus")
+ expect(authorLine.querySelector("time")).toHaveAttribute("datetime", "2026-09-04T00:00:00.000Z")
const messageContent = rows[0]!.querySelector("[data-community-message-body]")!
expect(messageContent.querySelector('[data-streamdown="strong"]')).toHaveTextContent("First")
expect(messageContent.querySelector("code")).toHaveTextContent("code")
diff --git a/src/web/src/components/community/social/bot-mark-sticker.tsx b/src/web/src/components/community/social/bot-mark-sticker.tsx
index b6229c074..24aac27eb 100644
--- a/src/web/src/components/community/social/bot-mark-sticker.tsx
+++ b/src/web/src/components/community/social/bot-mark-sticker.tsx
@@ -12,6 +12,7 @@ import { formatRelativeTime } from "@/lib/community/format-time"
import { tid } from "@/lib/community/testids"
import { Avatar } from "../avatar"
import { MessageBody } from "../messages/message-body"
+import { MessageAuthorLine } from "../messages/message-author-line"
import { BotAuditActiveRow } from "./bot-audit-preview"
import styles from "./bot-mark-sticker.module.css"
@@ -208,16 +209,12 @@ export function BotMarkSticker({
size={28}
/>
<div className="w-fit min-w-0 max-w-full">
- <div className="flex w-fit min-w-0 max-w-full items-center gap-2 text-xs leading-4">
- <span className="min-w-0 truncate font-semibold">
- {mark.m.authorName || "Deleted user"}
- </span>
- {mark.m.createdAt && (
- <time dateTime={mark.m.createdAt} className="shrink-0 whitespace-nowrap font-mono text-[9px] tabular-nums text-(--note-muted)">
- {formatRelativeTime(mark.m.createdAt)}
- </time>
- )}
- </div>
+ <MessageAuthorLine
+ variant="note"
+ authorName={mark.m.authorName || "Deleted user"}
+ timestamp={mark.m.createdAt ? formatRelativeTime(mark.m.createdAt) : undefined}
+ timestampProps={{ dateTime: mark.m.createdAt }}
+ />
<div title={location} className="flex w-fit min-w-0 max-w-full items-center gap-1 text-[10px] leading-4 text-(--note-muted)">
<span className={mark.serverId ? "min-w-0 truncate" : "shrink-0"}>
{locationPrefix}