Skip to content

Commit ac0d0cc

Browse files
committed
fix: refine types
1 parent 257295c commit ac0d0cc

File tree

12 files changed

+44
-44
lines changed

12 files changed

+44
-44
lines changed

package/expo-package/src/optionalDependencies/getPhotos.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Platform } from 'react-native';
22
import mime from 'mime';
33

4+
import type { File } from 'stream-chat-react-native-core';
5+
46
let MediaLibrary;
57

68
try {
@@ -14,12 +16,11 @@ if (!MediaLibrary) {
1416
'expo-media-library is not installed. Please install it or you can choose to install expo-image-picker for native image picker.',
1517
);
1618
}
17-
import type { RNFile } from 'stream-chat';
1819

1920
import { getLocalAssetUri } from './getLocalAssetUri';
2021

2122
type ReturnType = {
22-
assets: RNFile[];
23+
assets: File[];
2324
endCursor: string | undefined;
2425
hasNextPage: boolean;
2526
iOSLimited: boolean;

package/native-package/src/optionalDependencies/getPhotos.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PermissionsAndroid, Platform } from 'react-native';
22
import mime from 'mime';
3-
import { RNFile } from 'stream-chat';
3+
4+
import type { File } from 'stream-chat-react-native-core';
45

56
let CameraRollDependency;
67

@@ -16,7 +17,7 @@ try {
1617
import { getLocalAssetUri } from './getLocalAssetUri';
1718

1819
type ReturnType = {
19-
assets: RNFile[];
20+
assets: File[];
2021
endCursor: string | undefined;
2122
hasNextPage: boolean;
2223
iOSLimited: boolean;

package/src/components/AttachmentPicker/AttachmentPicker.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import type { BottomSheetHandleProps } from '@gorhom/bottom-sheet';
77
import dayjs from 'dayjs';
88
import duration from 'dayjs/plugin/duration';
99

10-
import { RNFile } from 'stream-chat';
11-
1210
import type { AttachmentPickerErrorProps } from './components/AttachmentPickerError';
1311

1412
import { renderAttachmentPickerItem } from './components/AttachmentPickerItem';
@@ -20,6 +18,7 @@ import {
2018
import { useTheme } from '../../contexts/themeContext/ThemeContext';
2119
import { useScreenDimensions } from '../../hooks/useScreenDimensions';
2220
import { NativeHandlers } from '../../native';
21+
import type { File } from '../../types/types';
2322
import { BottomSheet } from '../BottomSheetCompatibility/BottomSheet';
2423
import { BottomSheetFlatList } from '../BottomSheetCompatibility/BottomSheetFlatList';
2524

@@ -109,7 +108,7 @@ export const AttachmentPicker = React.forwardRef(
109108
const [iOSLimited, setIosLimited] = useState(false);
110109
const hasNextPageRef = useRef(true);
111110
const [loadingPhotos, setLoadingPhotos] = useState(false);
112-
const [photos, setPhotos] = useState<RNFile[]>([]);
111+
const [photos, setPhotos] = useState<File[]>([]);
113112
const attemptedToLoadPhotosOnOpenRef = useRef(false);
114113

115114
const getMorePhotos = useCallback(async () => {

package/src/components/AttachmentPicker/components/AttachmentPickerItem.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ import React from 'react';
22

33
import { Alert, ImageBackground, StyleSheet, Text, View } from 'react-native';
44

5-
import { RNFile } from 'stream-chat';
6-
75
import { AttachmentPickerContextValue } from '../../../contexts/attachmentPickerContext/AttachmentPickerContext';
86
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
97
import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext';
108
import { useViewport } from '../../../hooks/useViewport';
119
import { Recorder } from '../../../icons';
10+
import type { File } from '../../../types/types';
1211
import { getDurationLabelFromDuration } from '../../../utils/utils';
1312
import { BottomSheetTouchableOpacity } from '../../BottomSheetCompatibility/BottomSheetTouchableOpacity';
1413
type AttachmentPickerItemType = Pick<
1514
AttachmentPickerContextValue,
1615
'selectedFiles' | 'setSelectedFiles' | 'setSelectedImages' | 'selectedImages' | 'maxNumberOfFiles'
1716
> & {
18-
asset: RNFile;
17+
asset: File;
1918
ImageOverlaySelectedComponent: React.ComponentType;
2019
numberOfUploads: number;
2120
selected: boolean;
@@ -48,7 +47,7 @@ const AttachmentVideo = (props: AttachmentVideoProps) => {
4847

4948
const { duration: videoDuration, thumb_url, uri } = asset;
5049

51-
const durationLabel = getDurationLabelFromDuration(videoDuration);
50+
const durationLabel = videoDuration ? getDurationLabelFromDuration(videoDuration) : '00:00';
5251

5352
const size = vw(100) / (numberOfAttachmentPickerImageColumns || 3) - 2;
5453

package/src/components/MessageInput/hooks/useAudioController.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { useEffect, useRef, useState } from 'react';
22

33
import { Alert, Platform } from 'react-native';
44

5-
import { RNFile } from 'stream-chat';
6-
75
import { useMessageInputContext } from '../../../contexts/messageInputContext/MessageInputContext';
86
import {
97
AudioRecordingReturnType,
@@ -12,6 +10,7 @@ import {
1210
RecordingStatus,
1311
SoundReturnType,
1412
} from '../../../native';
13+
import type { File } from '../../../types/types';
1514
import { FileTypes } from '../../../types/types';
1615
import { resampleWaveformData } from '../utils/audioSampling';
1716
import { normalizeAudioLevel } from '../utils/normalizeAudioLevel';
@@ -267,7 +266,7 @@ export const useAudioController = () => {
267266
const clearFilter = new RegExp('[.:]', 'g');
268267
const date = new Date().toISOString().replace(clearFilter, '_');
269268

270-
const file: RNFile = {
269+
const file: File = {
271270
duration: durationInSeconds,
272271
name: `audio_recording_${date}.aac`,
273272
size: 0,

package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { PropsWithChildren, useContext, useEffect, useState } from 'react
22

33
import { BottomSheetHandleProps } from '@gorhom/bottom-sheet';
44

5-
import { RNFile } from 'stream-chat';
5+
import type { File } from '../../types/types';
66

77
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
88

@@ -82,12 +82,12 @@ export type AttachmentPickerContextValue = {
8282
*/
8383
maxNumberOfFiles: number;
8484
openPicker: () => void;
85-
selectedFiles: RNFile[];
86-
selectedImages: RNFile[];
85+
selectedFiles: File[];
86+
selectedImages: File[];
8787
setBottomInset: React.Dispatch<React.SetStateAction<number>>;
8888
setMaxNumberOfFiles: React.Dispatch<React.SetStateAction<number>>;
89-
setSelectedFiles: React.Dispatch<React.SetStateAction<RNFile[]>>;
90-
setSelectedImages: React.Dispatch<React.SetStateAction<RNFile[]>>;
89+
setSelectedFiles: React.Dispatch<React.SetStateAction<File[]>>;
90+
setSelectedImages: React.Dispatch<React.SetStateAction<File[]>>;
9191
setSelectedPicker: React.Dispatch<React.SetStateAction<'images' | undefined>>;
9292
setTopInset: React.Dispatch<React.SetStateAction<number>>;
9393
topInset: number;
@@ -125,8 +125,8 @@ export const AttachmentPickerProvider = ({
125125

126126
const [bottomInset, setBottomInset] = useState<number>(bottomInsetValue ?? 0);
127127
const [maxNumberOfFiles, setMaxNumberOfFiles] = useState(10);
128-
const [selectedImages, setSelectedImages] = useState<RNFile[]>([]);
129-
const [selectedFiles, setSelectedFiles] = useState<RNFile[]>([]);
128+
const [selectedImages, setSelectedImages] = useState<File[]>([]);
129+
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
130130
const [selectedPicker, setSelectedPicker] = useState<'images'>();
131131
const [topInset, setTopInset] = useState<number>(topInsetValue ?? 0);
132132

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
Attachment,
1515
logChatPromiseExecution,
1616
Message,
17-
RNFile,
1817
SendFileAPIResponse,
1918
StreamChat,
2019
Message as StreamMessage,
@@ -60,7 +59,7 @@ import {
6059
MediaTypes,
6160
NativeHandlers,
6261
} from '../../native';
63-
import { FileTypes, FileUpload } from '../../types/types';
62+
import { File, FileTypes, FileUpload } from '../../types/types';
6463
import {
6564
ACITriggerSettings,
6665
ACITriggerSettingsParams,
@@ -231,8 +230,8 @@ export type LocalMessageInputContext = {
231230
uploadFile: ({ newFile }: { newFile: FileUpload }) => Promise<void>;
232231
/** Function for attempting to upload an image */
233232
uploadImage: ({ newImage }: { newImage: FileUpload }) => Promise<void>;
234-
uploadNewFile: (file: RNFile, fileType?: FileTypes) => Promise<void>;
235-
uploadNewImage: (image: RNFile) => Promise<void>;
233+
uploadNewFile: (file: File, fileType?: FileTypes) => Promise<void>;
234+
uploadNewImage: (image: File) => Promise<void>;
236235
};
237236

238237
export type InputMessageInputContextValue = {
@@ -416,7 +415,7 @@ export type InputMessageInputContextValue = {
416415
* @overrideType Function
417416
*/
418417
doDocUploadRequest?: (
419-
file: RNFile,
418+
file: File,
420419
channel: ChannelContextValue['channel'],
421420
) => Promise<SendFileAPIResponse>;
422421

@@ -429,7 +428,7 @@ export type InputMessageInputContextValue = {
429428
* @overrideType Function
430429
*/
431430
doImageUploadRequest?: (
432-
file: RNFile,
431+
file: File,
433432
channel: ChannelContextValue['channel'],
434433
) => Promise<SendFileAPIResponse>;
435434

@@ -1320,7 +1319,7 @@ export const MessageInputProvider = ({
13201319
* This is useful for voice recordings, where the file type is not always detected correctly.
13211320
* This will change if we unify the file uploads to attachments.
13221321
*/
1323-
const uploadNewFile = async (file: RNFile, fileType?: FileTypes) => {
1322+
const uploadNewFile = async (file: File, fileType?: FileTypes) => {
13241323
try {
13251324
const id: string = generateRandomId();
13261325
const fileConfig = getFileUploadConfig();
@@ -1368,7 +1367,7 @@ export const MessageInputProvider = ({
13681367
}
13691368
};
13701369

1371-
const uploadNewImage = async (image: RNFile) => {
1370+
const uploadNewImage = async (image: File) => {
13721371
try {
13731372
const id = generateRandomId();
13741373
const imageUploadConfig = getImageUploadConfig();

package/src/contexts/messageInputContext/utils/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { lookup } from 'mime-types';
2-
import type { FileUploadConfig, RNFile } from 'stream-chat';
2+
import type { FileUploadConfig } from 'stream-chat';
3+
4+
import { File } from '../../../types/types';
35

46
export const MAX_FILE_SIZE_TO_UPLOAD = 100 * 1024 * 1024; // 100 MB
57

68
type CheckUploadPermissionsParams = {
79
config: FileUploadConfig;
8-
file: RNFile;
10+
file: File;
911
};
1012

1113
/**

package/src/native.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type React from 'react';
22
import { FlatList as DefaultFlatList, StyleProp, ViewStyle } from 'react-native';
33

4-
import { RNFile } from 'stream-chat';
5-
4+
import type { File } from './types/types';
65
const fail = () => {
76
throw Error(
87
'Native handler was not registered, you should import stream-chat-expo or stream-chat-react-native',
@@ -31,7 +30,7 @@ type iOS14RefreshGallerySelection = () => Promise<void>;
3130

3231
type GetPhotos = ({ after, first }: { first: number; after?: string }) =>
3332
| Promise<{
34-
assets: RNFile[];
33+
assets: File[];
3534
endCursor: string;
3635
hasNextPage: boolean;
3736
iOSLimited: boolean;
@@ -41,13 +40,13 @@ type GetPhotos = ({ after, first }: { first: number; after?: string }) =>
4140
type PickDocument = ({ maxNumberOfFiles }: { maxNumberOfFiles?: number }) =>
4241
| Promise<{
4342
cancelled: boolean;
44-
assets?: RNFile[];
43+
assets?: File[];
4544
}>
4645
| never;
4746

4847
type PickImageAssetType = {
4948
askToOpenSettings?: boolean;
50-
assets?: RNFile[];
49+
assets?: File[];
5150
cancelled?: boolean;
5251
};
5352

@@ -67,7 +66,7 @@ type ShareOptions = {
6766
};
6867
type ShareImage = (options: ShareOptions) => Promise<boolean> | never;
6968

70-
type TakePhotoFileType = RNFile & {
69+
type TakePhotoFileType = File & {
7170
askToOpenSettings?: boolean;
7271
cancelled?: boolean;
7372
};

package/src/types/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ export enum FileTypes {
1212
VoiceRecording = 'voiceRecording',
1313
}
1414

15+
export type File = RNFile;
16+
1517
/**
1618
* This is nothing but a substitute for the attachment type prior to sending the message.
1719
* This will change if we unify the file uploads to attachments.
1820
*/
1921
export type FileUpload = {
20-
file: RNFile;
22+
file: File;
2123
id: string;
2224
state: FileStateValue;
2325

@@ -44,8 +46,8 @@ export interface DefaultAttachmentType {
4446
duration?: number;
4547
file_size?: number;
4648
mime_type?: string;
47-
originalFile?: RNFile;
48-
originalImage?: RNFile;
49+
originalFile?: File;
50+
originalImage?: File;
4951
waveform_data?: number[];
5052
}
5153

0 commit comments

Comments
 (0)