Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(web): include message context in share images

Gus16e59f169737
diff --git a/src/web/src/components/community/message-share-dialog.test.ts b/src/web/src/components/community/message-share-dialog.test.ts
new file mode 100644
index 000000000..95752b567
--- /dev/null
+++ b/src/web/src/components/community/message-share-dialog.test.ts
@@ -0,0 +1,101 @@
+import { describe, expect, it, vi } from "vitest"
+import React from "react"
+import TestRenderer, { act } from "react-test-renderer"
+import { MessageShareDialog } from "./message-share-dialog"
+import type { RenderMsg } from "./_types"
+
+vi.mock("html-to-image", () => ({ toBlob: vi.fn() }))
+vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn() } }))
+vi.mock("next/image", () => ({ default: "img" }))
+vi.mock("./avatar", () => ({ Avatar: "mock-avatar" }))
+vi.mock("./message-body", () => ({ MessageBody: ({ text }: { text: string }) => text }))
+vi.mock("@/components/ui/button", () => ({ Button: "button" }))
+vi.mock("@/components/ui/dialog", () => {
+ const Passthrough = ({ children }: { children?: React.ReactNode }) => children
+ return {
+ Dialog: Passthrough,
+ DialogContent: Passthrough,
+ DialogHeader: Passthrough,
+ DialogTitle: Passthrough,
+ }
+})
+
+function message(overrides: Partial<RenderMsg> = {}): RenderMsg {
+ return {
+ id: "m1",
+ type: "chat",
+ authorId: "u1",
+ authorName: "Alice",
+ content: "Current message",
+ grouped: false,
+ ...overrides,
+ }
+}
+
+function renderMessage(m: RenderMsg) {
+ let renderer: TestRenderer.ReactTestRenderer
+ act(() => {
+ renderer = TestRenderer.create(React.createElement(MessageShareDialog, {
+ m,
+ open: true,
+ onClose: vi.fn(),
+ }))
+ })
+ return renderer!
+}
+
+describe("MessageShareDialog message context", () => {
+ it("renders the reply author and plain-text excerpt above the shared message", () => {
+ const renderer = renderMessage(message({
+ replyTo: {
+ id: "original",
+ authorName: "Bob",
+ text: "A **formatted** reply",
+ },
+ }))
+
+ const reply = renderer.root.findByProps({ "data-testid": "message-share-reply-m1" })
+ const spans = reply.findAllByType("span")
+ expect(spans.map((span) => span.children.join(""))).toEqual([
+ "@Bob",
+ "A formatted reply",
+ ])
+ })
+
+ it("renders the deleted-original state without stale reply details", () => {
+ const renderer = renderMessage(message({
+ replyTo: {
+ id: "original",
+ authorName: "Bob",
+ text: "Stale content",
+ deleted: true,
+ },
+ }))
+
+ const reply = renderer.root.findByProps({ "data-testid": "message-share-reply-m1" })
+ const text = reply.findAllByType("span").map((span) => span.children.join(""))
+ expect(text).toEqual(["Original message was deleted"])
+ })
+
+ it("renders every emoji reaction with its count", () => {
+ const renderer = renderMessage(message({
+ reactions: [
+ { emoji: "πŸ‘", count: 2, me: true, userIds: ["u1", "u2"] },
+ { emoji: "πŸŽ‰", count: 11, me: false, userIds: [] },
+ ],
+ }))
+
+ const reactions = renderer.root.findByProps({ "data-testid": "message-share-reactions-m1" })
+ const text = reactions.findAllByType("span").map((span) => span.children.join(""))
+ expect(text).toEqual(expect.arrayContaining(["πŸ‘", "2", "πŸŽ‰", "11"]))
+ })
+
+ it("does not add empty context containers", () => {
+ const renderer = renderMessage(message())
+ const contexts = renderer.root.findAll((node) => (
+ typeof node.props["data-testid"] === "string"
+ && node.props["data-testid"].startsWith("message-share-")
+ ))
+ expect(contexts).toHaveLength(0)
+ })
+})
diff --git a/src/web/src/components/community/message-share-dialog.tsx b/src/web/src/components/community/message-share-dialog.tsx
index 27dd17226..fcf675a93 100644
--- a/src/web/src/components/community/message-share-dialog.tsx
+++ b/src/web/src/components/community/message-share-dialog.tsx
@@ -5,6 +5,7 @@ import Image from "next/image"
import { toBlob } from "html-to-image"
import { toast } from "sonner"
import { Check, Copy, Download, Highlighter, Loader2 } from "lucide-react"
+import { stripInlineMarkup } from "@alook/shared"
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Avatar } from "./avatar"
@@ -169,41 +170,76 @@ export function MessageShareDialog({ m, open, onClose }: {
className="rounded-xl bg-card p-5 shadow-(--e1)"
>
{messages.map((msg) => (
- // A grouped message (consecutive same author) collapses the avatar
- // column into a spacer + drops the name, matching the chat stream.
- <div key={msg.id} className={`flex gap-3 ${msg.grouped ? "mt-0.5" : "mt-3 first:mt-0"}`}>
- {msg.grouped
- ? <div className="w-10 shrink-0" aria-hidden />
- : <Avatar label={msg.authorAvatar ?? "?"} seed={msg.authorId} size={40} />}
- <div className="min-w-0 flex-1">
- {!msg.grouped && (
- <div
- className="mb-0.5 text-[15px] font-semibold"
- style={{ color: msg.color ?? "var(--foreground)" }}
- >
- {msg.authorName}
- </div>
- )}
- {/* Each body: clamp at 32 lines (Alli #137 β€” one number for
- single & multi share). Two layers, same as the original
- single-message card: `max-h` hard-bounds any structure
- (multi-paragraph markdown escapes line-clamp alone), and
- `line-clamp-[32]` gives a single-block message a tidy
- ellipsis. Each body also drives its own drag-highlight
- (per-message scope, Alli #133) via its ref in `bodyRefs`;
- the `mark[data-hl]` styles are the soft-yellow marker
- (rasterises cleanly under html-to-image β€” plain bg +
- box-decoration-break, no mask). max-h β‰ˆ 32 lines at the
- body's 15px/leading-snug. */}
- {msg.content && (
- <div
- ref={(el) => { bodyRefs.current.set(msg.id, el) }}
- onMouseUp={() => onBodyMouseUp(msg.id)}
- className="max-h-164 overflow-hidden line-clamp-32 [&_mark[data-hl]]:rounded-xs [&_mark[data-hl]]:bg-[rgba(255,208,92,0.5)] [&_mark[data-hl]]:p-[0_1px] [&_mark[data-hl]]:[box-decoration-break:clone] [&_mark[data-hl]]:[-webkit-box-decoration-break:clone] [&_mark[data-hl]]:text-inherit"
- >
- <MessageBody text={msg.content} perspective="neutral" />
- </div>
- )}
+ <div key={msg.id} className={msg.grouped ? "mt-0.5" : "mt-3 first:mt-0"}>
+ {msg.replyTo && (
+ <div
+ data-testid={`message-share-reply-${msg.id}`}
+ className="mb-1 ml-13 flex min-w-0 max-w-[calc(100%-3.25rem)] items-center gap-2 text-[13px] text-muted-foreground"
+ >
+ <div className="h-2 w-4 shrink-0 rounded-tl-md border-l-2 border-t-2 border-border" />
+ {msg.replyTo.deleted ? (
+ <span className="italic">Original message was deleted</span>
+ ) : (
+ <>
+ <span className="shrink-0 font-medium text-foreground/80">@{msg.replyTo.authorName}</span>
+ <span className="min-w-0 truncate">{stripInlineMarkup(msg.replyTo.text)}</span>
+ </>
+ )}
+ </div>
+ )}
+ <div className="flex gap-3">
+ {msg.grouped
+ ? <div className="w-10 shrink-0" aria-hidden />
+ : <Avatar label={msg.authorAvatar ?? "?"} seed={msg.authorId} size={40} />}
+ <div className="min-w-0 flex-1">
+ {!msg.grouped && (
+ <div
+ className="mb-0.5 text-[15px] font-semibold"
+ style={{ color: msg.color ?? "var(--foreground)" }}
+ >
+ {msg.authorName}
+ </div>
+ )}
+ {/* Each body: clamp at 32 lines (Alli #137 β€” one number for
+ single & multi share). Two layers, same as the original
+ single-message card: `max-h` hard-bounds any structure
+ (multi-paragraph markdown escapes line-clamp alone), and
+ `line-clamp-[32]` gives a single-block message a tidy
+ ellipsis. Each body also drives its own drag-highlight
+ (per-message scope, Alli #133) via its ref in `bodyRefs`;
+ the `mark[data-hl]` styles are the soft-yellow marker
+ (rasterises cleanly under html-to-image β€” plain bg +
+ box-decoration-break, no mask). max-h β‰ˆ 32 lines at the
+ body's 15px/leading-snug. */}
+ {msg.content && (
+ <div
+ ref={(el) => { bodyRefs.current.set(msg.id, el) }}
+ onMouseUp={() => onBodyMouseUp(msg.id)}
+ className="max-h-164 overflow-hidden line-clamp-32 [&_mark[data-hl]]:rounded-xs [&_mark[data-hl]]:bg-[rgba(255,208,92,0.5)] [&_mark[data-hl]]:p-[0_1px] [&_mark[data-hl]]:[box-decoration-break:clone] [&_mark[data-hl]]:[-webkit-box-decoration-break:clone] [&_mark[data-hl]]:text-inherit"
+ >
+ <MessageBody text={msg.content} perspective="neutral" />
+ </div>
+ )}
+ {msg.reactions && msg.reactions.length > 0 && (
+ <div
+ data-testid={`message-share-reactions-${msg.id}`}
+ className="mt-2 flex flex-wrap gap-1"
+ >
+ {msg.reactions.map((reaction) => (
+ <span
+ key={reaction.emoji}
+ className={[
+ "flex h-6 items-center gap-1 rounded-md px-2 text-sm",
+ reaction.me ? "border border-primary/50 bg-accent" : "bg-secondary",
+ ].join(" ")}
+ >
+ <span>{reaction.emoji}</span>
+ <span className="text-xs text-muted-foreground">{reaction.count}</span>
+ </span>
+ ))}
+ </div>
+ )}
+ </div>
</div>
</div>
))}