Skip to content

Commit 8e96b6c

Browse files
committed
chore: remove attachment identity functions supported by stream-chat-js
1 parent bdc2bab commit 8e96b6c

File tree

2 files changed

+8
-68
lines changed

2 files changed

+8
-68
lines changed

src/components/Attachment/Attachment.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React, { useMemo } from 'react';
22
import {
33
isAudioAttachment,
4+
isFileAttachment,
45
isImageAttachment,
56
isScrapedContent,
7+
isVideoAttachment,
68
isVoiceRecordingAttachment,
79
} from 'stream-chat';
810

@@ -16,7 +18,7 @@ import {
1618
UnsupportedAttachmentContainer,
1719
VoiceRecordingContainer,
1820
} from './AttachmentContainer';
19-
import { isFileAttachment, isMediaAttachment } from './utils';
21+
import { SUPPORTED_VIDEO_FORMATS } from './utils';
2022

2123
import type { ReactPlayerProps } from 'react-player';
2224
import type { Attachment as StreamAttachment } from 'stream-chat';
@@ -164,13 +166,13 @@ const getAttachmentType = (
164166
): keyof typeof CONTAINER_MAP => {
165167
if (isScrapedContent(attachment)) {
166168
return 'card';
167-
} else if (isMediaAttachment(attachment)) {
169+
} else if (isVideoAttachment(attachment, SUPPORTED_VIDEO_FORMATS)) {
168170
return 'media';
169171
} else if (isAudioAttachment(attachment)) {
170172
return 'audio';
171173
} else if (isVoiceRecordingAttachment(attachment)) {
172174
return 'voiceRecording';
173-
} else if (isFileAttachment(attachment)) {
175+
} else if (isFileAttachment(attachment, SUPPORTED_VIDEO_FORMATS)) {
174176
return 'file';
175177
}
176178

src/components/Attachment/utils.tsx

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
import 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';
123
import type { ATTACHMENT_GROUPS_ORDER, AttachmentProps } from './Attachment';
134

145
export 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
5331
export 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-
9836
export const isSvgAttachment = (attachment: Attachment) => {
9937
const filename = attachment.fallback || '';
10038
return filename.toLowerCase().endsWith('.svg');

0 commit comments

Comments
 (0)