@linktr.ee/messaging-react 3.5.5-rc-1783057111 → 3.5.5-rc-1783225142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/{Card-DIKCis8o.cjs → Card-1DoFXFYW.cjs} +2 -2
  2. package/dist/{Card-DIKCis8o.cjs.map → Card-1DoFXFYW.cjs.map} +1 -1
  3. package/dist/{Card-Bwy7V0Bo.cjs → Card-BZ9-Tfh_.cjs} +2 -2
  4. package/dist/{Card-Bwy7V0Bo.cjs.map → Card-BZ9-Tfh_.cjs.map} +1 -1
  5. package/dist/{Card-DAk82C-r.js → Card-Buz9UKi0.js} +2 -2
  6. package/dist/{Card-DAk82C-r.js.map → Card-Buz9UKi0.js.map} +1 -1
  7. package/dist/{Card-1aop9_6f.js → Card-DXTYHy7j.js} +3 -3
  8. package/dist/{Card-1aop9_6f.js.map → Card-DXTYHy7j.js.map} +1 -1
  9. package/dist/{Card-Cy37m6vt.cjs → Card-DlvxBaiE.cjs} +2 -2
  10. package/dist/{Card-Cy37m6vt.cjs.map → Card-DlvxBaiE.cjs.map} +1 -1
  11. package/dist/{Card-B8TOdDxd.js → Card-DsJKjQM_.js} +2 -2
  12. package/dist/{Card-B8TOdDxd.js.map → Card-DsJKjQM_.js.map} +1 -1
  13. package/dist/{LockedThumbnail-BnCxeG99.js → LockedThumbnail-BQaJBYQi.js} +2 -2
  14. package/dist/{LockedThumbnail-BnCxeG99.js.map → LockedThumbnail-BQaJBYQi.js.map} +1 -1
  15. package/dist/{LockedThumbnail-D5SVLnl9.cjs → LockedThumbnail-CoXe3AwW.cjs} +2 -2
  16. package/dist/{LockedThumbnail-D5SVLnl9.cjs.map → LockedThumbnail-CoXe3AwW.cjs.map} +1 -1
  17. package/dist/index-BRsofS9i.cjs +2 -0
  18. package/dist/index-BRsofS9i.cjs.map +1 -0
  19. package/dist/{index-erdzinja.js → index-BZlD16ar.js} +3425 -3155
  20. package/dist/index-BZlD16ar.js.map +1 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +1 -1
  23. package/package.json +2 -2
  24. package/src/components/CustomLinkPreviewList/index.tsx +6 -12
  25. package/src/components/CustomMessage/StreamAttachmentMessage.test.tsx +109 -0
  26. package/src/components/CustomMessage/StreamAttachmentMessage.tsx +408 -0
  27. package/src/components/CustomMessage/index.tsx +42 -0
  28. package/src/components/CustomMessageInput/index.tsx +4 -7
  29. package/dist/index-OEDMXEKk.cjs +0 -2
  30. package/dist/index-OEDMXEKk.cjs.map +0 -1
  31. package/dist/index-erdzinja.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-OEDMXEKk.cjs");exports.ActionButton=e.ActionButton;exports.Avatar=e.Avatar;exports.ChannelEmptyState=e.ChannelEmptyState;exports.ChannelList=e.ChannelList;exports.ChannelView=e.ChannelView;exports.CustomMessageProvider=e.CustomMessageProvider;exports.FaqList=e.FaqList;exports.FaqListItem=e.FaqListItem;exports.LinkAttachment=e.LinkAttachment;exports.LockedAttachment=e.LockedAttachment;exports.MediaMessage=e.MediaMessage;exports.MessageAttachment=e.MessageAttachment;exports.MessageVoteButtons=e.MessageVoteButtons;exports.MessagingProvider=e.MessagingProvider;exports.MessagingShell=e.MessagingShell;exports.buildCompactMetaLabel=e.buildCompactMetaLabel;exports.formatFileSize=e.formatFileSize;exports.formatRelativeTime=e.formatRelativeTime;exports.getFileExtensionLabel=e.getFileExtensionLabel;exports.getMessageDisplayText=e.getMessageDisplayText;exports.isLinkAttachment=e.isLinkAttachment;exports.isUuidLike=e.isUuidLike;exports.messageAttachmentGroupPositionFromStream=e.bubbleGroupPositionFromStream;exports.normalizeLanguageCode=e.normalizeLanguageCode;exports.resolveConversationParticipant=e.resolveConversationParticipant;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useComposerLocked=e.useComposerLocked;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-BRsofS9i.cjs");exports.ActionButton=e.ActionButton;exports.Avatar=e.Avatar;exports.ChannelEmptyState=e.ChannelEmptyState;exports.ChannelList=e.ChannelList;exports.ChannelView=e.ChannelView;exports.CustomMessageProvider=e.CustomMessageProvider;exports.FaqList=e.FaqList;exports.FaqListItem=e.FaqListItem;exports.LinkAttachment=e.LinkAttachment;exports.LockedAttachment=e.LockedAttachment;exports.MediaMessage=e.MediaMessage;exports.MessageAttachment=e.MessageAttachment;exports.MessageVoteButtons=e.MessageVoteButtons;exports.MessagingProvider=e.MessagingProvider;exports.MessagingShell=e.MessagingShell;exports.buildCompactMetaLabel=e.buildCompactMetaLabel;exports.formatFileSize=e.formatFileSize;exports.formatRelativeTime=e.formatRelativeTime;exports.getFileExtensionLabel=e.getFileExtensionLabel;exports.getMessageDisplayText=e.getMessageDisplayText;exports.isLinkAttachment=e.isLinkAttachment;exports.isUuidLike=e.isUuidLike;exports.messageAttachmentGroupPositionFromStream=e.bubbleGroupPositionFromStream;exports.normalizeLanguageCode=e.normalizeLanguageCode;exports.resolveConversationParticipant=e.resolveConversationParticipant;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useComposerLocked=e.useComposerLocked;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as d, m as p, n as v, o as C, p as A, q as k, s as F, t as P, u as b, v as f, w as x, x as y, y as S, z as q, B as z, D as B, E as D, G as E } from "./index-erdzinja.js";
1
+ import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as d, m as p, n as v, o as C, p as A, q as k, s as F, t as P, u as b, v as f, w as x, x as y, y as S, z as q, B as z, D as B, E as D, G as E } from "./index-BZlD16ar.js";
2
2
  export {
3
3
  e as ActionButton,
4
4
  t as Avatar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linktr.ee/messaging-react",
3
- "version": "3.5.5-rc-1783057111",
3
+ "version": "3.5.5-rc-1783225142",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@linktr.ee/component-library": "11.8.6",
41
- "@linktr.ee/messaging-core": "2.3.0-rc-1783057111",
41
+ "@linktr.ee/messaging-core": "2.3.0-rc-1783225142",
42
42
  "@phosphor-icons/react": "^2.1.10"
43
43
  },
44
44
  "devDependencies": {
@@ -32,19 +32,13 @@ export const CustomLinkPreviewList = () => {
32
32
  if (!showLinkPreviews) return null
33
33
 
34
34
  return (
35
- // Layout contract: this list is the composer's *shrinkable* region. The
36
- // mobile visitor surface sizes itself to the keyboard-shrunk
37
- // visualViewport, so when vertical space runs out this container gives
38
- // way (min-h-0) and scrolls, while the textarea + send row stays visible
39
- // (shrink-0 in CustomMessageInput). Each card is wrapped in a shrink-0
40
- // block so it keeps its intrinsic height and the container scrolls — a
41
- // bare flex-column child would be shrunk on the column axis and its
42
- // fixed-height hero would spill out of the collapsed card box.
43
- <div className="messaging-link-preview-list flex min-h-0 flex-col items-stretch w-full gap-2 mb-4 overflow-y-auto overscroll-contain">
35
+ <div className="flex flex-col items-stretch w-full gap-2 mb-4">
44
36
  {stateLinkPreviews.map((linkPreview) => (
45
- <div key={linkPreview.og_scrape_url} className="w-full shrink-0">
46
- <CustomLinkPreviewCard link={linkPreview} onDismiss={handleDismiss} />
47
- </div>
37
+ <CustomLinkPreviewCard
38
+ key={linkPreview.og_scrape_url}
39
+ link={linkPreview}
40
+ onDismiss={handleDismiss}
41
+ />
48
42
  ))}
49
43
  </div>
50
44
  )
@@ -0,0 +1,109 @@
1
+ import React from 'react'
2
+ import { describe, expect, it } from 'vitest'
3
+
4
+ import { renderWithProviders, screen } from '../../test/utils'
5
+
6
+ import StreamAttachmentMessage, {
7
+ linkCaptionDuplicatesAttachmentUrl,
8
+ } from './StreamAttachmentMessage'
9
+
10
+ describe('linkCaptionDuplicatesAttachmentUrl', () => {
11
+ it('suppresses captions that are just the link plus punctuation', () => {
12
+ expect(
13
+ linkCaptionDuplicatesAttachmentUrl(
14
+ 'https://tr.ee/abc !',
15
+ 'https://tr.ee/abc'
16
+ )
17
+ ).toBe(true)
18
+ })
19
+
20
+ it('keeps captions that add emoji after the link', () => {
21
+ expect(
22
+ linkCaptionDuplicatesAttachmentUrl(
23
+ 'https://tr.ee/abc 😎',
24
+ 'https://tr.ee/abc'
25
+ )
26
+ ).toBe(false)
27
+ })
28
+ })
29
+
30
+ describe('StreamAttachmentMessage', () => {
31
+ it('renders a sent link card and suppresses a URL-only caption', () => {
32
+ renderWithProviders(
33
+ <StreamAttachmentMessage
34
+ groupPosition="single"
35
+ isMyMessage={true}
36
+ message={{
37
+ attachments: [
38
+ {
39
+ type: 'link',
40
+ og_scrape_url: 'https://linktr.ee/someone',
41
+ title: 'My Linktree',
42
+ text: 'Check out my links',
43
+ image_url: 'https://cdn.example.com/thumb.jpg',
44
+ },
45
+ ],
46
+ text: 'https://linktr.ee/someone !',
47
+ }}
48
+ />
49
+ )
50
+
51
+ expect(
52
+ screen.getByRole('link', { name: /my linktree/i })
53
+ ).toHaveAttribute('href', 'https://linktr.ee/someone')
54
+ expect(screen.queryByText('https://linktr.ee/someone !')).toBeNull()
55
+ })
56
+
57
+ it('keeps an emoji-only caption instead of dropping it', () => {
58
+ renderWithProviders(
59
+ <StreamAttachmentMessage
60
+ groupPosition="single"
61
+ isMyMessage={false}
62
+ message={{
63
+ attachments: [
64
+ {
65
+ type: 'link',
66
+ og_scrape_url: 'https://linktr.ee/someone',
67
+ title: 'My Linktree',
68
+ },
69
+ ],
70
+ text: 'https://linktr.ee/someone 😎',
71
+ }}
72
+ />
73
+ )
74
+
75
+ expect(screen.getByText('https://linktr.ee/someone 😎')).toBeInTheDocument()
76
+ })
77
+
78
+ it('renders mixed link and media attachments in order', () => {
79
+ const { container } = renderWithProviders(
80
+ <StreamAttachmentMessage
81
+ groupPosition="single"
82
+ isMyMessage={true}
83
+ message={{
84
+ attachments: [
85
+ {
86
+ type: 'link',
87
+ og_scrape_url: 'https://linktr.ee/someone',
88
+ title: 'My Linktree',
89
+ },
90
+ {
91
+ type: 'image',
92
+ image_url: 'https://cdn.example.com/photo.jpg',
93
+ title: 'Vacation',
94
+ },
95
+ ],
96
+ text: 'caption',
97
+ }}
98
+ />
99
+ )
100
+
101
+ const link = screen.getByRole('link', { name: /my linktree/i })
102
+ const imageBubble = screen.getByTestId('image-attachment')
103
+
104
+ expect(link.compareDocumentPosition(imageBubble)).toBe(
105
+ Node.DOCUMENT_POSITION_FOLLOWING
106
+ )
107
+ expect(container).toHaveTextContent('caption')
108
+ })
109
+ })
@@ -0,0 +1,408 @@
1
+ import React from 'react'
2
+ import type { Attachment } from 'stream-chat'
3
+
4
+ import LinkAttachment from '../LinkAttachment'
5
+ import MessageAttachment from '../MessageAttachment'
6
+ import type { BubbleGroupPosition } from '../MessageAttachment/types'
7
+
8
+ type StreamMediaKind = 'image' | 'video' | 'audio' | 'pdf' | 'file'
9
+
10
+ export type AttachmentSegment =
11
+ | { type: 'link'; attachments: Attachment[] }
12
+ | { type: 'media'; kind: StreamMediaKind; attachments: Attachment[] }
13
+
14
+ type StreamThreadMessage = {
15
+ attachments?: Attachment[]
16
+ text?: string
17
+ }
18
+
19
+ const SENT_CAPTION_CLASS =
20
+ 'mt-[2px] max-w-[280px] whitespace-pre-wrap break-words rounded-[18px] bg-[#121110] px-4 py-2 text-white'
21
+ const RECEIVED_CAPTION_CLASS =
22
+ 'mt-[2px] max-w-[280px] whitespace-pre-wrap break-words rounded-[18px] bg-[#e9eaed] px-4 py-2 text-[#080707]'
23
+
24
+ function trimToUndefined(value?: string | null): string | undefined {
25
+ const trimmed = value?.trim()
26
+ return trimmed ? trimmed : undefined
27
+ }
28
+
29
+ export function normalizeLinkUrl(url: string): string {
30
+ return url
31
+ .trim()
32
+ .replace(/^https?:\/\//i, '')
33
+ .replace(/\/+$/, '')
34
+ .toLowerCase()
35
+ }
36
+
37
+ export function linkCaptionDuplicatesAttachmentUrl(
38
+ caption: string | undefined,
39
+ attachmentUrl?: string
40
+ ): boolean {
41
+ if (!caption?.trim() || !attachmentUrl?.trim()) {
42
+ return false
43
+ }
44
+
45
+ const normalizedCaption = normalizeLinkUrl(caption)
46
+ const normalizedUrl = normalizeLinkUrl(attachmentUrl)
47
+
48
+ if (normalizedCaption === normalizedUrl) {
49
+ return true
50
+ }
51
+
52
+ if (!normalizedCaption.includes(normalizedUrl)) {
53
+ return false
54
+ }
55
+
56
+ const remainder = normalizedCaption.split(normalizedUrl).join('')
57
+ return !/[^\p{P}\p{Z}\p{C}]/u.test(remainder)
58
+ }
59
+
60
+ export function linkCardPropsFromStreamAttachment(a: Attachment) {
61
+ const url = trimToUndefined(a.og_scrape_url) ?? trimToUndefined(a.title_link)
62
+ const thumbnailUrl =
63
+ trimToUndefined((a as { image_url?: string }).image_url) ??
64
+ trimToUndefined((a as { thumb_url?: string }).thumb_url)
65
+
66
+ return {
67
+ title: trimToUndefined((a as { title?: string }).title),
68
+ description: trimToUndefined((a as { text?: string }).text),
69
+ url,
70
+ thumbnailUrl,
71
+ layout: thumbnailUrl ? 'featured' : 'classic',
72
+ mimeType: trimToUndefined(a.mime_type),
73
+ } as const
74
+ }
75
+
76
+ export function getAttachmentMediaKind(
77
+ attachment: Attachment
78
+ ): StreamMediaKind | null {
79
+ if (isLinkAttachment(attachment)) return null
80
+
81
+ if (attachment.type === 'image') {
82
+ const imageUrl = (attachment as { image_url?: string }).image_url
83
+ if (imageUrl || attachment.asset_url) return 'image'
84
+ return null
85
+ }
86
+
87
+ if (attachment.type === 'video' && attachment.asset_url) return 'video'
88
+ if (attachment.type === 'audio' && attachment.asset_url) return 'audio'
89
+
90
+ if (attachment.type === 'file' && attachment.asset_url) {
91
+ if (attachment.mime_type === 'application/pdf') return 'pdf'
92
+ if (attachment.mime_type?.startsWith('audio/')) return 'audio'
93
+ return 'file'
94
+ }
95
+
96
+ return null
97
+ }
98
+
99
+ export function isLinkAttachment(a: Attachment): boolean {
100
+ const ogScrapeUrl = trimToUndefined(a.og_scrape_url)
101
+ return a.type === 'link' || (!!ogScrapeUrl && !a.asset_url)
102
+ }
103
+
104
+ export function buildOrderedAttachmentSegments(
105
+ attachments: Attachment[] | undefined
106
+ ): AttachmentSegment[] {
107
+ if (!attachments?.length) return []
108
+
109
+ const segments: AttachmentSegment[] = []
110
+
111
+ const pushOrMergeMedia = (kind: StreamMediaKind, attachment: Attachment) => {
112
+ const last = segments[segments.length - 1]
113
+ if (last?.type === 'media' && last.kind === kind) {
114
+ last.attachments.push(attachment)
115
+ return
116
+ }
117
+
118
+ segments.push({ type: 'media', kind, attachments: [attachment] })
119
+ }
120
+
121
+ const pushOrMergeLink = (attachment: Attachment) => {
122
+ const last = segments[segments.length - 1]
123
+ if (last?.type === 'link') {
124
+ last.attachments.push(attachment)
125
+ return
126
+ }
127
+
128
+ segments.push({ type: 'link', attachments: [attachment] })
129
+ }
130
+
131
+ for (const attachment of attachments) {
132
+ if (isLinkAttachment(attachment)) {
133
+ pushOrMergeLink(attachment)
134
+ continue
135
+ }
136
+
137
+ const kind = getAttachmentMediaKind(attachment)
138
+ if (!kind) continue
139
+
140
+ pushOrMergeMedia(kind, attachment)
141
+ }
142
+
143
+ return segments
144
+ }
145
+
146
+ export function countAttachmentSegmentBubbles(
147
+ segments: AttachmentSegment[]
148
+ ): number {
149
+ let count = 0
150
+
151
+ for (const segment of segments) {
152
+ count += segment.type === 'link' ? segment.attachments.length : 1
153
+ }
154
+
155
+ return count
156
+ }
157
+
158
+ export function countMediaSegmentBubbles(segments: AttachmentSegment[]): number {
159
+ return segments.filter((segment) => segment.type === 'media').length
160
+ }
161
+
162
+ export function bubblePositionInRun(
163
+ index: number,
164
+ total: number,
165
+ streamPosition: BubbleGroupPosition
166
+ ): BubbleGroupPosition {
167
+ if (total <= 1) return streamPosition
168
+ if (index === 0) return 'first'
169
+ if (index === total - 1) return 'end'
170
+ return 'middle'
171
+ }
172
+
173
+ function imageSrcFromAttachment(attachment: Attachment): string {
174
+ return (
175
+ trimToUndefined((attachment as { image_url?: string }).image_url) ??
176
+ trimToUndefined(attachment.asset_url) ??
177
+ ''
178
+ )
179
+ }
180
+
181
+ function messageAttachmentNamespaceForKind(kind: StreamMediaKind) {
182
+ switch (kind) {
183
+ case 'image':
184
+ return MessageAttachment.Image
185
+ case 'video':
186
+ return MessageAttachment.Video
187
+ case 'audio':
188
+ return MessageAttachment.Audio
189
+ case 'pdf':
190
+ return MessageAttachment.Pdf
191
+ default:
192
+ return MessageAttachment.File
193
+ }
194
+ }
195
+
196
+ function buildMediaClusterRenderProps(
197
+ kind: StreamMediaKind,
198
+ attachments: Attachment[]
199
+ ): Record<string, unknown> {
200
+ if (attachments.length > 1) {
201
+ switch (kind) {
202
+ case 'image':
203
+ return {
204
+ items: attachments.map((attachment) => ({
205
+ src: imageSrcFromAttachment(attachment),
206
+ alt: trimToUndefined((attachment as { title?: string }).title),
207
+ })),
208
+ }
209
+ case 'video':
210
+ return {
211
+ items: attachments.map((attachment) => ({
212
+ src: trimToUndefined(attachment.asset_url) ?? '',
213
+ poster: trimToUndefined(
214
+ (attachment as { thumb_url?: string }).thumb_url
215
+ ),
216
+ mimeType: trimToUndefined(attachment.mime_type),
217
+ })),
218
+ }
219
+ case 'audio':
220
+ return {
221
+ items: attachments.map((attachment) => ({
222
+ src: trimToUndefined(attachment.asset_url) ?? '',
223
+ mimeType:
224
+ trimToUndefined(attachment.mime_type) ?? 'audio/mpeg',
225
+ filename: trimToUndefined(
226
+ (attachment as { title?: string }).title
227
+ ),
228
+ })),
229
+ }
230
+ case 'pdf':
231
+ return {
232
+ items: attachments.map((attachment) => ({
233
+ src: trimToUndefined(attachment.asset_url) ?? '',
234
+ filename: trimToUndefined(
235
+ (attachment as { title?: string }).title
236
+ ),
237
+ fileSize: (attachment as { file_size?: number }).file_size,
238
+ })),
239
+ }
240
+ case 'file':
241
+ return {
242
+ items: attachments.map((attachment) => ({
243
+ src: trimToUndefined(attachment.asset_url) ?? '',
244
+ filename: trimToUndefined(
245
+ (attachment as { title?: string }).title
246
+ ),
247
+ fileSize: (attachment as { file_size?: number }).file_size,
248
+ mimeType:
249
+ trimToUndefined(attachment.mime_type) ??
250
+ 'application/octet-stream',
251
+ })),
252
+ }
253
+ }
254
+ }
255
+
256
+ const attachment = attachments[0]
257
+ if (!attachment) return {}
258
+
259
+ switch (kind) {
260
+ case 'image':
261
+ return {
262
+ src: imageSrcFromAttachment(attachment),
263
+ alt: trimToUndefined((attachment as { title?: string }).title),
264
+ }
265
+ case 'video':
266
+ return {
267
+ src: trimToUndefined(attachment.asset_url) ?? '',
268
+ poster: trimToUndefined((attachment as { thumb_url?: string }).thumb_url),
269
+ mimeType: trimToUndefined(attachment.mime_type),
270
+ }
271
+ case 'audio':
272
+ return {
273
+ src: trimToUndefined(attachment.asset_url) ?? '',
274
+ mimeType: trimToUndefined(attachment.mime_type) ?? 'audio/mpeg',
275
+ filename: trimToUndefined((attachment as { title?: string }).title),
276
+ }
277
+ case 'pdf':
278
+ return {
279
+ src: trimToUndefined(attachment.asset_url) ?? '',
280
+ filename: trimToUndefined((attachment as { title?: string }).title),
281
+ fileSize: (attachment as { file_size?: number }).file_size,
282
+ }
283
+ case 'file':
284
+ return {
285
+ src: trimToUndefined(attachment.asset_url) ?? '',
286
+ filename: trimToUndefined((attachment as { title?: string }).title),
287
+ fileSize: (attachment as { file_size?: number }).file_size,
288
+ mimeType:
289
+ trimToUndefined(attachment.mime_type) ?? 'application/octet-stream',
290
+ }
291
+ }
292
+ }
293
+
294
+ function MediaClusterBubble({
295
+ groupPosition,
296
+ isMyMessage,
297
+ segment,
298
+ text,
299
+ }: {
300
+ groupPosition: BubbleGroupPosition
301
+ isMyMessage: boolean
302
+ segment: Extract<AttachmentSegment, { type: 'media' }>
303
+ text?: string
304
+ }) {
305
+ const TypeNamespace = messageAttachmentNamespaceForKind(segment.kind)
306
+ const props = {
307
+ ...buildMediaClusterRenderProps(segment.kind, segment.attachments),
308
+ groupPosition,
309
+ ...(text ? { text } : {}),
310
+ }
311
+
312
+ if (isMyMessage) {
313
+ return <TypeNamespace.Sent {...props} />
314
+ }
315
+
316
+ return <TypeNamespace.Received {...props} />
317
+ }
318
+
319
+ export interface StreamAttachmentMessageProps {
320
+ groupPosition: BubbleGroupPosition
321
+ isMyMessage: boolean
322
+ message: StreamThreadMessage
323
+ }
324
+
325
+ const StreamAttachmentMessage: React.FC<StreamAttachmentMessageProps> = ({
326
+ groupPosition,
327
+ isMyMessage,
328
+ message,
329
+ }) => {
330
+ const segments = buildOrderedAttachmentSegments(message.attachments)
331
+ if (segments.length === 0) return null
332
+
333
+ const totalBubbles = countAttachmentSegmentBubbles(segments)
334
+ const totalMediaBubbles = countMediaSegmentBubbles(segments)
335
+ const rawCaption = message.text?.trim()
336
+ const linkSegment = segments.find((segment) => segment.type === 'link')
337
+ const primaryLinkUrl =
338
+ linkSegment?.type === 'link'
339
+ ? linkCardPropsFromStreamAttachment(linkSegment.attachments[0] ?? {}).url
340
+ : undefined
341
+ const caption =
342
+ rawCaption &&
343
+ linkCaptionDuplicatesAttachmentUrl(rawCaption, primaryLinkUrl)
344
+ ? undefined
345
+ : rawCaption
346
+
347
+ let bubbleIndex = 0
348
+ let mediaBubbleIndex = 0
349
+ const rows: React.ReactNode[] = []
350
+
351
+ const pushLinkRow = (attachment: Attachment, key: string) => {
352
+ const isLastBubble = bubbleIndex === totalBubbles - 1
353
+ bubbleIndex += 1
354
+
355
+ const Card = isMyMessage ? LinkAttachment.Sent : LinkAttachment.Received
356
+
357
+ rows.push(
358
+ <React.Fragment key={key}>
359
+ <Card {...linkCardPropsFromStreamAttachment(attachment)} />
360
+ {isLastBubble && caption ? (
361
+ <div className={isMyMessage ? SENT_CAPTION_CLASS : RECEIVED_CAPTION_CLASS}>
362
+ {caption}
363
+ </div>
364
+ ) : null}
365
+ </React.Fragment>
366
+ )
367
+ }
368
+
369
+ const pushMediaCluster = (
370
+ segment: Extract<AttachmentSegment, { type: 'media' }>,
371
+ key: string
372
+ ) => {
373
+ const isLastBubble = bubbleIndex === totalBubbles - 1
374
+ const position = bubblePositionInRun(
375
+ mediaBubbleIndex,
376
+ totalMediaBubbles,
377
+ groupPosition
378
+ )
379
+
380
+ bubbleIndex += 1
381
+ mediaBubbleIndex += 1
382
+
383
+ rows.push(
384
+ <MediaClusterBubble
385
+ key={key}
386
+ groupPosition={position}
387
+ isMyMessage={isMyMessage}
388
+ segment={segment}
389
+ text={isLastBubble ? caption : undefined}
390
+ />
391
+ )
392
+ }
393
+
394
+ segments.forEach((segment, segmentIndex) => {
395
+ if (segment.type === 'link') {
396
+ segment.attachments.forEach((attachment, attachmentIndex) => {
397
+ pushLinkRow(attachment, `link-${segmentIndex}-${attachmentIndex}`)
398
+ })
399
+ return
400
+ }
401
+
402
+ pushMediaCluster(segment, `media-${segmentIndex}`)
403
+ })
404
+
405
+ return <>{rows}</>
406
+ }
407
+
408
+ export default StreamAttachmentMessage
@@ -34,6 +34,9 @@ import { getMessageDisplayText } from '../../utils/getMessageDisplayText'
34
34
  import { Avatar } from '../Avatar'
35
35
  import LockedAttachment from '../LockedAttachment'
36
36
  import { isLinkAttachment } from '../MediaMessage'
37
+ import {
38
+ bubbleGroupPositionFromStream as messageAttachmentGroupPositionFromStream,
39
+ } from '../MessageAttachment'
37
40
 
38
41
  import { useCustomMessage } from './context'
39
42
  import {
@@ -43,6 +46,9 @@ import {
43
46
  isTipOnlyMessage,
44
47
  } from './MessageTag'
45
48
  import { MessageVoteButtons } from './MessageVoteButtons'
49
+ import StreamAttachmentMessage, {
50
+ buildOrderedAttachmentSegments,
51
+ } from './StreamAttachmentMessage'
46
52
 
47
53
  type CustomMessageUIComponentProps = MessageUIComponentProps & {
48
54
  chatbotVotingEnabled?: boolean
@@ -113,12 +119,26 @@ const CustomMessageWithContext = (props: CustomMessageWithContextProps) => {
113
119
  const filtered = raw.filter((a) => !('type' in a) || !isLinkAttachment(a))
114
120
  return filtered.length === raw.length ? raw : filtered
115
121
  }, [message])
122
+ const attachmentSegments = useMemo(
123
+ () => buildOrderedAttachmentSegments(finalAttachments),
124
+ [finalAttachments]
125
+ )
116
126
  const displayMessage = useMemo(() => {
117
127
  const displayText = getMessageDisplayText({ message, viewerLanguage })
118
128
  return displayText === message.text
119
129
  ? message
120
130
  : { ...message, text: displayText }
121
131
  }, [message, viewerLanguage])
132
+ const hasLinkAttachmentSegments = attachmentSegments.some(
133
+ (segment) => segment.type === 'link'
134
+ )
135
+ const streamAttachmentGroupPosition = messageAttachmentGroupPositionFromStream(
136
+ {
137
+ endOfGroup,
138
+ firstOfGroup,
139
+ groupedByUser,
140
+ }
141
+ )
122
142
 
123
143
  if (isDateSeparatorMessage(message)) {
124
144
  return null
@@ -279,6 +299,28 @@ const CustomMessageWithContext = (props: CustomMessageWithContextProps) => {
279
299
  ) : isTipOnly ? (
280
300
  /* Tip-only messages render as a standalone bubble */
281
301
  <MessageTag message={message} standalone />
302
+ ) : hasLinkAttachmentSegments ? (
303
+ <div className="str-chat__message-bubble-wrapper">
304
+ <div
305
+ className="str-chat__message-bubble"
306
+ style={{
307
+ background: 'transparent',
308
+ borderRadius: 0,
309
+ overflow: 'visible',
310
+ padding: 0,
311
+ }}
312
+ >
313
+ <StreamAttachmentMessage
314
+ groupPosition={streamAttachmentGroupPosition}
315
+ isMyMessage={isMine}
316
+ message={{
317
+ attachments: finalAttachments,
318
+ text: displayMessage.text,
319
+ }}
320
+ />
321
+ <MessageErrorIcon />
322
+ </div>
323
+ </div>
282
324
  ) : (
283
325
  <div className="str-chat__message-bubble-wrapper">
284
326
  <div className="str-chat__message-bubble">
@@ -61,17 +61,14 @@ const CustomMessageInputInner: React.FC = () => {
61
61
  } = useComponentContext('CustomMessageInput')
62
62
 
63
63
  return (
64
- // min-h-0 lets the composer shrink under keyboard squeeze (the link
65
- // preview list inside is the scrollable region); the textarea + send row
66
- // is shrink-0 so it can never be pushed out of view.
67
64
  <div
68
- className="central-container flex min-h-0 flex-col gap-2 min-w-0 w-full p-2 bg-white rounded-[1.5rem] shadow-[0_4px_16px_0_rgba(0,0,0,0.08),0_1px_2px_0_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.04)]"
65
+ className="central-container flex flex-col gap-2 min-w-0 w-full p-2 bg-white rounded-[1.5rem] shadow-[0_4px_16px_0_rgba(0,0,0,0.08),0_1px_2px_0_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.04)]"
69
66
  data-dd-privacy="mask"
70
67
  >
71
68
  <QuotedMessagePreview />
72
69
  <CustomLinkPreviewList />
73
70
  <AttachmentPreviewList />
74
- <div className="flex shrink-0">
71
+ <div className="flex">
75
72
  <div className="w-full ml-2 mr-4 self-center leading-[0]">
76
73
  <TextareaComposer
77
74
  aria-disabled={disabled || undefined}
@@ -158,12 +155,12 @@ export const CustomMessageInput: React.FC<CustomMessageInputProps> = ({
158
155
  }
159
156
 
160
157
  return (
161
- <div className="flex min-h-0 flex-col gap-4 p-4">
158
+ <div className="flex flex-col gap-4 p-4">
162
159
  <div
163
160
  // @ts-expect-error Only React 19 onwards has `inert` in its types.
164
161
  inert={isFrozen ? '' : undefined}
165
162
  aria-disabled={isFrozen || undefined}
166
- className="message-input flex min-h-0 items-end gap-4 aria-disabled:opacity-40"
163
+ className="message-input flex items-end gap-4 aria-disabled:opacity-40"
167
164
  >
168
165
  {renderActions && (
169
166
  <div className="flex h-12 shrink-0 items-center justify-center">