@@ -9,8 +9,12 @@ import {
99 isVideoAttachment ,
1010 isVoiceRecordingAttachment ,
1111 type Attachment as AttachmentType ,
12+ type LocalMessage ,
1213} from 'stream-chat' ;
1314
15+ import type { AudioAttachmentProps } from './Audio/AudioAttachment' ;
16+ import { AttachmentFileUploadProgressIndicator } from '../../components/Attachment/AttachmentFileUploadProgressIndicator' ;
17+
1418import { useTheme } from '../../contexts' ;
1519import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext' ;
1620import {
@@ -21,9 +25,11 @@ import {
2125 MessagesContextValue ,
2226 useMessagesContext ,
2327} from '../../contexts/messagesContext/MessagesContext' ;
28+ import { usePendingAttachmentUpload } from '../../hooks/usePendingAttachmentUpload' ;
2429import { isSoundPackageAvailable , isVideoPlayerAvailable } from '../../native' ;
2530
2631import { primitives } from '../../theme' ;
32+ import type { DefaultAttachmentData } from '../../types/types' ;
2733import { FileTypes } from '../../types/types' ;
2834
2935export type ActionHandler = ( name : string , value : string ) => void ;
@@ -83,12 +89,12 @@ const AttachmentWithContext = (props: AttachmentPropsWithContext) => {
8389 if ( isAudioAttachment ( attachment ) || isVoiceRecordingAttachment ( attachment ) ) {
8490 if ( isSoundPackageAvailable ( ) ) {
8591 return (
86- < AudioAttachment
87- item = { { ...attachment , id : index ?. toString ( ) ?? '' , type : attachment . type } }
92+ < MessageAudioAttachment
93+ AudioAttachment = { AudioAttachment }
94+ attachment = { attachment }
95+ audioAttachmentStyles = { audioAttachmentStyles }
96+ index = { index }
8897 message = { message }
89- showSpeedSettings = { true }
90- showTitle = { false }
91- styles = { audioAttachmentStyles }
9298 />
9399 ) ;
94100 }
@@ -166,6 +172,45 @@ export const Attachment = (props: AttachmentProps) => {
166172 ) ;
167173} ;
168174
175+ type MessageAudioAttachmentProps = {
176+ AudioAttachment : React . ComponentType < AudioAttachmentProps > ;
177+ attachment : AttachmentType ;
178+ audioAttachmentStyles : AudioAttachmentProps [ 'styles' ] ;
179+ index ?: number ;
180+ message : LocalMessage | undefined ;
181+ } ;
182+
183+ const MessageAudioAttachment = ( {
184+ AudioAttachment : AudioAttachmentComponent ,
185+ attachment,
186+ audioAttachmentStyles,
187+ index,
188+ message,
189+ } : MessageAudioAttachmentProps ) => {
190+ const localId = ( attachment as DefaultAttachmentData ) . localId ;
191+ const { isUploading, uploadProgress } = usePendingAttachmentUpload ( localId ) ;
192+
193+ const indicator = isUploading ? (
194+ < AttachmentFileUploadProgressIndicator
195+ totalBytes = { attachment . file_size }
196+ uploadProgress = { uploadProgress }
197+ />
198+ ) : undefined ;
199+
200+ const audioItemType = isVoiceRecordingAttachment ( attachment ) ? 'voiceRecording' : 'audio' ;
201+
202+ return (
203+ < AudioAttachmentComponent
204+ indicator = { indicator }
205+ item = { { ...attachment , id : index ?. toString ( ) ?? '' , type : audioItemType } }
206+ message = { message }
207+ showSpeedSettings = { true }
208+ showTitle = { false }
209+ styles = { audioAttachmentStyles }
210+ />
211+ ) ;
212+ } ;
213+
169214const useAudioAttachmentStyles = ( ) => {
170215 const {
171216 theme : { semantics } ,
0 commit comments