Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): match shared images to message previews

Gusca4400c83f38
diff --git a/src/web/src/components/community/message-menu-parity.test.ts b/src/web/src/components/community/message-menu-parity.test.ts
index cec17c09b..64964475b 100644
--- a/src/web/src/components/community/message-menu-parity.test.ts
+++ b/src/web/src/components/community/message-menu-parity.test.ts
@@ -30,8 +30,25 @@ describe("messageCanShare β€” the derivation that gives every surface Share", ()
expect(messageCanShare(msg(), undefined)).toBe(true)
})
+ it("offers Share for an image-only message", () => {
+ expect(messageCanShare(msg({
+ content: "",
+ attachments: [{
+ kind: "image",
+ name: "photo.png",
+ url: "/photo.png",
+ width: 640,
+ height: 480,
+ }],
+ }), false)).toBe(true)
+ })
+
it("withholds Share when there's nothing to put on the card", () => {
expect(messageCanShare(msg({ content: "" }), false)).toBe(false)
+ expect(messageCanShare(msg({
+ content: "",
+ attachments: [{ kind: "file", name: "notes.txt", url: "/notes.txt", size: "1 KB" }],
+ }), false)).toBe(false)
expect(messageCanShare(msg({ approval: {} as RenderMsg["approval"] }), false)).toBe(false)
expect(messageCanShare(msg(), true)).toBe(false) // compact rows opt out
})
diff --git a/src/web/src/components/community/message-share-dialog.test.ts b/src/web/src/components/community/message-share-dialog.test.ts
index 95752b567..00c3010c4 100644
--- a/src/web/src/components/community/message-share-dialog.test.ts
+++ b/src/web/src/components/community/message-share-dialog.test.ts
@@ -90,6 +90,55 @@ describe("MessageShareDialog message context", () => {
expect(text).toEqual(expect.arrayContaining(["πŸ‘", "2", "πŸŽ‰", "11"]))
})
+ it("renders attached originals at their intrinsic ratio and omits files", () => {
+ const renderer = renderMessage(message({
+ attachments: [
+ {
+ kind: "image",
+ name: "photo.png",
+ url: "/original-photo.png",
+ thumbnailUrl: "/thumbnail-photo.jpg",
+ width: 1200,
+ height: 800,
+ },
+ { kind: "file", name: "notes.txt", url: "/notes.txt", size: "1 KB" },
+ ],
+ }))
+
+ const image = renderer.root.findByProps({ "data-testid": "message-share-image-m1-0" })
+ expect(image.props).toMatchObject({
+ src: "/original-photo.png",
+ alt: "photo.png",
+ width: 1200,
+ height: 800,
+ loading: "eager",
+ style: { aspectRatio: "1200/800" },
+ })
+ expect(image.props.className).toContain("max-h-75")
+ expect(image.props.className).toContain("max-w-full")
+ expect(image.props.className).toContain("rounded-lg")
+ expect(image.props.className).toContain("object-contain")
+ expect(image.parent?.props.className).toContain("w-fit")
+ expect(image.parent?.props.className).toContain("max-w-full")
+ expect(image.parent?.props.className).toContain("rounded-lg")
+ expect(image.parent?.props.className).toContain("border")
+ expect(renderer.root.findAllByProps({ src: "/notes.txt" })).toHaveLength(0)
+ })
+
+ it("keeps image previews above reactions like the live message", () => {
+ const renderer = renderMessage(message({
+ content: "",
+ attachments: [{ kind: "image", name: "photo.png", url: "/photo.png" }],
+ reactions: [{ emoji: "πŸ‘", count: 2, me: false, userIds: [] }],
+ }))
+
+ const contextOrder = renderer.root.findAll((node) => (
+ typeof node.props["data-testid"] === "string"
+ && ["message-share-images-m1", "message-share-reactions-m1"].includes(node.props["data-testid"])
+ )).map((node) => node.props["data-testid"])
+ expect(contextOrder).toEqual(["message-share-images-m1", "message-share-reactions-m1"])
+ })
+
it("does not add empty context containers", () => {
const renderer = renderMessage(message())
const contexts = renderer.root.findAll((node) => (
diff --git a/src/web/src/components/community/message-share-dialog.tsx b/src/web/src/components/community/message-share-dialog.tsx
index fcf675a93..3a7630d2f 100644
--- a/src/web/src/components/community/message-share-dialog.tsx
+++ b/src/web/src/components/community/message-share-dialog.tsx
@@ -10,6 +10,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/u
import { Button } from "@/components/ui/button"
import { Avatar } from "./avatar"
import { MessageBody } from "./message-body"
+import { attachmentAspectRatio } from "./attachment-layout"
import { tid } from "@/lib/community/testids"
import { applyHighlightToRange, clearHighlights, hasHighlights } from "@/lib/community/highlight-range"
import type { RenderMsg } from "./_types"
@@ -220,6 +221,32 @@ export function MessageShareDialog({ m, open, onClose }: {
<MessageBody text={msg.content} perspective="neutral" />
</div>
)}
+ {msg.attachments?.some((attachment) => attachment.kind === "image") && (
+ <div
+ data-testid={`message-share-images-${msg.id}`}
+ className="mt-2 flex flex-col gap-2"
+ >
+ {msg.attachments.map((attachment, index) => (
+ attachment.kind === "image" && (
+ <div
+ key={`${attachment.name}-${index}`}
+ className="w-fit max-w-full overflow-hidden rounded-lg border border-border"
+ >
+ <img
+ data-testid={`message-share-image-${msg.id}-${index}`}
+ src={attachment.url}
+ alt={attachment.name}
+ width={attachment.width}
+ height={attachment.height}
+ loading="eager"
+ className="block h-auto w-auto max-h-75 max-w-full rounded-lg object-contain"
+ style={{ aspectRatio: attachmentAspectRatio(attachment.width, attachment.height) }}
+ />
+ </div>
+ )
+ ))}
+ </div>
+ )}
{msg.reactions && msg.reactions.length > 0 && (
<div
data-testid={`message-share-reactions-${msg.id}`}
diff --git a/src/web/src/components/community/message.tsx b/src/web/src/components/community/message.tsx
index 079d859f8..abba28f14 100644
--- a/src/web/src/components/community/message.tsx
+++ b/src/web/src/components/community/message.tsx
@@ -30,11 +30,13 @@ import { attachmentAspectRatio } from "./attachment-layout"
// the right-click / long-press context menu, and the #N-ref context sheet β€”
// inherits an identical action menu. Extracted as a pure predicate so that
// menu-parity guarantee is directly testable. A share card mirrors
-// avatar/name/content, so it's meaningful only for a non-compact message that
-// has rendered text (an approval- or attachment-only row has nothing to put on
-// the card).
+// avatar/name/content/images, so it's meaningful only for a non-compact message
+// that has rendered text or at least one image attachment. File-only and
+// approval rows still have no visual message content for the card.
export function messageCanShare(m: RenderMsg, compact?: boolean): boolean {
- return !compact && !m.approval && !!m.content
+ return !compact
+ && !m.approval
+ && (!!m.content || !!m.attachments?.some((attachment) => attachment.kind === "image"))
}
export function shouldActivateMessageOverlays(target: EventTarget | null): boolean {