11import type { ReactNode } from 'react' ;
2- import type {
3- Attachment ,
4- LocalAttachment ,
5- LocalAudioAttachment ,
6- LocalImageAttachment ,
7- LocalVoiceRecordingAttachment ,
8- VoiceRecordingAttachment ,
9- } from 'stream-chat' ;
10-
11- import type { LocalFileAttachment , LocalVideoAttachment } from 'stream-chat' ;
2+ import type { Attachment } from 'stream-chat' ;
123import type { ATTACHMENT_GROUPS_ORDER , AttachmentProps } from './Attachment' ;
134
145export const SUPPORTED_VIDEO_FORMATS = [
@@ -35,66 +26,13 @@ export type RenderGalleryProps = Omit<AttachmentProps, 'attachments'> & {
3526 attachment : GalleryAttachment ;
3627} ;
3728
38- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39- export const isLocalAttachment = ( attachment : any ) : attachment is LocalAttachment =>
40- ! ! ( attachment as LocalAttachment ) . localMetadata ?. id ;
41-
42- export const isScrapedContent = ( attachment : Attachment ) =>
43- attachment . og_scrape_url || attachment . title_link ;
44-
45- export const isUploadedImage = ( attachment : Attachment ) =>
46- attachment . type === 'image' && ! isScrapedContent ( attachment ) ;
47-
48- export const isLocalImageAttachment = (
49- attachment : Attachment | LocalAttachment ,
50- ) : attachment is LocalImageAttachment =>
51- isUploadedImage ( attachment ) && isLocalAttachment ( attachment ) ;
52-
29+ // This identity function determines attachment type specific to React.
30+ // Once made sure other SDKs support the same logic, move to stream-chat-js
5331export const isGalleryAttachmentType = (
5432 attachment : Attachment | GalleryAttachment ,
5533) : attachment is GalleryAttachment =>
5634 Array . isArray ( ( attachment as GalleryAttachment ) . images ) ;
5735
58- export const isAudioAttachment = ( attachment : Attachment | LocalAttachment ) =>
59- attachment . type === 'audio' ;
60-
61- export const isLocalAudioAttachment = (
62- attachment : Attachment | LocalAttachment ,
63- ) : attachment is LocalAudioAttachment =>
64- isAudioAttachment ( attachment ) && isLocalAttachment ( attachment ) ;
65-
66- export const isVoiceRecordingAttachment = (
67- attachment : Attachment | LocalAttachment ,
68- ) : attachment is VoiceRecordingAttachment => attachment . type === 'voiceRecording' ;
69-
70- export const isLocalVoiceRecordingAttachment = (
71- attachment : Attachment | LocalAttachment ,
72- ) : attachment is LocalVoiceRecordingAttachment =>
73- isVoiceRecordingAttachment ( attachment ) && isLocalAttachment ( attachment ) ;
74-
75- export const isFileAttachment = ( attachment : Attachment | LocalAttachment ) =>
76- attachment . type === 'file' ||
77- ! ! (
78- attachment . mime_type &&
79- SUPPORTED_VIDEO_FORMATS . indexOf ( attachment . mime_type ) === - 1 &&
80- attachment . type !== 'video'
81- ) ;
82-
83- export const isLocalFileAttachment = (
84- attachment : Attachment | LocalAttachment ,
85- ) : attachment is LocalFileAttachment =>
86- isFileAttachment ( attachment ) && isLocalAttachment ( attachment ) ;
87-
88- export const isMediaAttachment = ( attachment : Attachment | LocalAttachment ) =>
89- ( attachment . mime_type &&
90- SUPPORTED_VIDEO_FORMATS . indexOf ( attachment . mime_type ) !== - 1 ) ||
91- attachment . type === 'video' ;
92-
93- export const isLocalMediaAttachment = (
94- attachment : Attachment | LocalAttachment ,
95- ) : attachment is LocalVideoAttachment =>
96- isMediaAttachment ( attachment ) && isLocalAttachment ( attachment ) ;
97-
9836export const isSvgAttachment = ( attachment : Attachment ) => {
9937 const filename = attachment . fallback || '' ;
10038 return filename . toLowerCase ( ) . endsWith ( '.svg' ) ;
0 commit comments