Skip to content

Commit 0dd0fb5

Browse files
committed
feat: remove deprecated APIs and props for the central audio player change
1 parent 51992be commit 0dd0fb5

File tree

16 files changed

+269
-859
lines changed

16 files changed

+269
-859
lines changed

package/src/components/Attachment/AudioAttachment.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313

1414
import { useTheme } from '../../contexts';
1515
import { useStateStore } from '../../hooks';
16-
import { useAudioPlayerControl } from '../../hooks/useAudioPlayerControl';
16+
import { useAudioPlayer } from '../../hooks/useAudioPlayer';
1717
import { Audio, Pause, Play } from '../../icons';
1818
import {
1919
NativeHandlers,
@@ -56,21 +56,6 @@ export type AudioAttachmentProps = {
5656
* If true, the audio attachment is in preview mode in the message input.
5757
*/
5858
isPreview?: boolean;
59-
/**
60-
* Callback to be called when the audio is loaded
61-
* @deprecated This is deprecated and will be removed in the future.
62-
*/
63-
onLoad?: (index: string, duration: number) => void;
64-
/**
65-
* Callback to be called when the audio is played or paused
66-
* @deprecated This is deprecated and will be removed in the future.
67-
*/
68-
onPlayPause?: (index: string, pausedStatus?: boolean) => void;
69-
/**
70-
* Callback to be called when the audio progresses
71-
* @deprecated This is deprecated and will be removed in the future.
72-
*/
73-
onProgress?: (index: string, progress: number) => void;
7459
};
7560

7661
const audioPlayerSelector = (state: AudioPlayerState) => ({
@@ -99,7 +84,7 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
9984
} = props;
10085
const isVoiceRecording = isVoiceRecordingAttachment(item);
10186

102-
const audioPlayer = useAudioPlayerControl({
87+
const audioPlayer = useAudioPlayer({
10388
duration: item.duration ?? 0,
10489
mimeType: item.mime_type ?? '',
10590
requester: isPreview
@@ -269,10 +254,8 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
269254
/>
270255
) : (
271256
<ProgressControl
272-
duration={duration}
273257
filledColor={accent_blue}
274258
onEndDrag={dragEnd}
275-
onProgressDrag={dragProgress}
276259
onStartDrag={dragStart}
277260
progress={progress}
278261
testID='progress-control'

package/src/components/Attachment/FileAttachmentGroup.tsx

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ import { isSoundPackageAvailable } from '../../native';
1919

2020
export type FileAttachmentGroupPropsWithContext = Pick<MessageContextValue, 'files' | 'message'> &
2121
Pick<MessagesContextValue, 'Attachment' | 'AudioAttachment'> & {
22-
/**
23-
* @deprecated Use message instead
24-
* The unique id for the message with file attachments
25-
*/
26-
messageId: string;
2722
styles?: Partial<{
2823
attachmentContainer: StyleProp<ViewStyle>;
2924
container: StyleProp<ViewStyle>;
@@ -49,68 +44,6 @@ const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithConte
4944
);
5045
}, [files]);
5146

52-
/**
53-
* Handler triggered when an audio is loaded in the message input. The initial state is defined for the audio here and the duration is set.
54-
* @param index - The index of the audio
55-
* @param duration - The duration of the audio
56-
*
57-
* @deprecated This is deprecated and will be removed in the future.
58-
* FIXME: Remove this in the next major version.
59-
*/
60-
const onLoad = (index: string, duration: number) => {
61-
setFilesToDisplay((prevFilesToDisplay) =>
62-
prevFilesToDisplay.map((fileToDisplay, id) => ({
63-
...fileToDisplay,
64-
duration: id.toString() === index ? duration : fileToDisplay.duration,
65-
})),
66-
);
67-
};
68-
69-
/**
70-
* Handler which is triggered when the audio progresses/ the thumb is dragged in the progress control. The progressed duration is set here.
71-
* @param index - The index of the audio
72-
* @param progress - The progress of the audio
73-
*
74-
* @deprecated This is deprecated and will be removed in the future.
75-
* FIXME: Remove this in the next major version.
76-
*/
77-
const onProgress = (index: string, progress: number) => {
78-
setFilesToDisplay((prevFilesToDisplay) =>
79-
prevFilesToDisplay.map((filesToDisplay, id) => ({
80-
...filesToDisplay,
81-
progress: id.toString() === index ? progress : filesToDisplay.progress,
82-
})),
83-
);
84-
};
85-
86-
/**
87-
* Handler which controls or sets the paused/played state of the audio.
88-
* @param index - The index of the audio
89-
* @param pausedStatus - The paused status of the audio
90-
*
91-
* @deprecated This is deprecated and will be removed in the future.
92-
* FIXME: Remove this in the next major version.
93-
*/
94-
const onPlayPause = (index: string, pausedStatus?: boolean) => {
95-
if (pausedStatus === false) {
96-
// If the status is false we set the audio with the index as playing and the others as paused.
97-
setFilesToDisplay((prevFilesToDisplay) =>
98-
prevFilesToDisplay.map((fileToDisplay, id) => ({
99-
...fileToDisplay,
100-
paused: id.toString() !== index,
101-
})),
102-
);
103-
} else {
104-
// If the status is true we simply set all the audio's paused state as true.
105-
setFilesToDisplay((prevFilesToDisplay) =>
106-
prevFilesToDisplay.map((fileToDisplay) => ({
107-
...fileToDisplay,
108-
paused: true,
109-
})),
110-
);
111-
}
112-
};
113-
11447
const {
11548
theme: {
11649
messageSimple: {
@@ -135,9 +68,6 @@ const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithConte
13568
<AudioAttachment
13669
item={{ ...file, id: index.toString(), type: file.type }}
13770
message={message}
138-
onLoad={onLoad}
139-
onPlayPause={onPlayPause}
140-
onProgress={onProgress}
14171
showSpeedSettings={true}
14272
/>
14373
) : (
@@ -169,13 +99,10 @@ const MemoizedFileAttachmentGroup = React.memo(
16999
areEqual,
170100
) as typeof FileAttachmentGroupWithContext;
171101

172-
export type FileAttachmentGroupProps = Partial<
173-
Omit<FileAttachmentGroupPropsWithContext, 'messageId'>
174-
> &
175-
Pick<FileAttachmentGroupPropsWithContext, 'messageId'>;
102+
export type FileAttachmentGroupProps = Partial<FileAttachmentGroupPropsWithContext>;
176103

177104
export const FileAttachmentGroup = (props: FileAttachmentGroupProps) => {
178-
const { files: propFiles, messageId } = props;
105+
const { files: propFiles } = props;
179106

180107
const { files: contextFiles, message } = useMessageContext();
181108

@@ -194,7 +121,6 @@ export const FileAttachmentGroup = (props: FileAttachmentGroupProps) => {
194121
AudioAttachment,
195122
files,
196123
message,
197-
messageId,
198124
}}
199125
/>
200126
);

package/src/components/ImageGallery/components/ImageGalleryVideoControl.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export const ImageGalleryVideoControl = React.memo(
9494
</Text>
9595
<View style={styles.progressContainer}>
9696
<ProgressControl
97-
duration={duration}
9897
filledColor={accent_blue}
9998
progress={progress}
10099
testID={'progress-control'}

package/src/components/Message/MessageSimple/MessageContent.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,7 @@ const MessageContentWithContext = (props: MessageContentPropsWithContext) => {
322322
));
323323
case 'files':
324324
return (
325-
<FileAttachmentGroup
326-
key={`file_attachment_group_${messageContentOrderIndex}`}
327-
messageId={message.id}
328-
/>
325+
<FileAttachmentGroup key={`file_attachment_group_${messageContentOrderIndex}`} />
329326
);
330327
case 'gallery':
331328
return <Gallery key={`gallery_${messageContentOrderIndex}`} />;

package/src/components/MessageInput/AttachmentUploadPreviewList.tsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import {
1111
LocalImageAttachment,
1212
} from 'stream-chat';
1313

14-
import { useAudioPreviewManager } from './hooks/useAudioPreviewManager';
15-
1614
import { useMessageComposer } from '../../contexts';
1715
import { useAttachmentManagerState } from '../../contexts/messageInputContext/hooks/useAttachmentManagerState';
1816
import {
@@ -64,15 +62,6 @@ const UnMemoizedAttachmentUploadListPreview = (
6462
const fileUploads = useMemo(() => {
6563
return attachments.filter((attachment) => !isLocalImageAttachment(attachment));
6664
}, [attachments]);
67-
const audioUploads = useMemo(() => {
68-
return fileUploads.filter(
69-
(attachment) =>
70-
isLocalAudioAttachment(attachment) || isLocalVoiceRecordingAttachment(attachment),
71-
);
72-
}, [fileUploads]);
73-
74-
const { audioAttachmentsStateMap, onLoad, onProgress, onPlayPause } =
75-
useAudioPreviewManager(audioUploads);
7665

7766
const renderImageItem = useCallback(
7867
({ item }: { item: LocalImageAttachment }) => {
@@ -100,11 +89,7 @@ const UnMemoizedAttachmentUploadListPreview = (
10089
return (
10190
<AudioAttachmentUploadPreview
10291
attachment={item}
103-
audioAttachmentConfig={audioAttachmentsStateMap[item.localMetadata.id]}
10492
handleRetry={attachmentManager.uploadAttachment}
105-
onLoad={onLoad}
106-
onPlayPause={onPlayPause}
107-
onProgress={onProgress}
10893
removeAttachments={attachmentManager.removeAttachments}
10994
/>
11095
);
@@ -113,11 +98,7 @@ const UnMemoizedAttachmentUploadListPreview = (
11398
return (
11499
<AudioAttachmentUploadPreview
115100
attachment={item}
116-
audioAttachmentConfig={audioAttachmentsStateMap[item.localMetadata.id]}
117101
handleRetry={attachmentManager.uploadAttachment}
118-
onLoad={onLoad}
119-
onPlayPause={onPlayPause}
120-
onProgress={onProgress}
121102
removeAttachments={attachmentManager.removeAttachments}
122103
/>
123104
);
@@ -157,11 +138,7 @@ const UnMemoizedAttachmentUploadListPreview = (
157138
VideoAttachmentUploadPreview,
158139
attachmentManager.removeAttachments,
159140
attachmentManager.uploadAttachment,
160-
audioAttachmentsStateMap,
161141
flatListWidth,
162-
onLoad,
163-
onPlayPause,
164-
onProgress,
165142
],
166143
);
167144

package/src/components/MessageInput/MessageInput.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Animated, {
1818

1919
import { type MessageComposerState, type TextComposerState, type UserResponse } from 'stream-chat';
2020

21-
import { useAudioController } from './hooks/useAudioController';
21+
import { useAudioRecorder } from './hooks/useAudioRecorder';
2222
import { useCountdown } from './hooks/useCountdown';
2323

2424
import { ChatContextValue, useChatContext, useOwnCapabilitiesContext } from '../../contexts';
@@ -311,11 +311,7 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
311311
const {
312312
deleteVoiceRecording,
313313
micLocked,
314-
onVoicePlayerPlayPause,
315-
paused,
316314
permissionsGranted,
317-
position,
318-
progress,
319315
recording,
320316
recordingDuration,
321317
recordingStatus,
@@ -324,7 +320,7 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
324320
stopVoiceRecording,
325321
uploadVoiceRecording,
326322
waveformData,
327-
} = useAudioController();
323+
} = useAudioRecorder();
328324

329325
const asyncAudioEnabled = audioRecordingEnabled && isAudioRecorderAvailable();
330326
const showSendingButton = hasText || attachments.length || command;
@@ -449,10 +445,6 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
449445
/>
450446
{recordingStatus === 'stopped' ? (
451447
<AudioRecordingPreview
452-
onVoicePlayerPlayPause={onVoicePlayerPlayPause}
453-
paused={paused}
454-
position={position}
455-
progress={progress}
456448
recordingDuration={recordingDuration}
457449
uri={
458450
typeof recording !== 'string'

package/src/components/MessageInput/components/AttachmentPreview/AudioAttachmentUploadPreview.tsx

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,18 @@ import { DismissAttachmentUpload } from './DismissAttachmentUpload';
1111
import { AudioAttachment } from '../../../../components/Attachment/AudioAttachment';
1212
import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
1313
import { useMessageComposer } from '../../../../contexts/messageInputContext/hooks/useMessageComposer';
14-
import { AudioConfig, UploadAttachmentPreviewProps } from '../../../../types/types';
14+
import { UploadAttachmentPreviewProps } from '../../../../types/types';
1515
import { getIndicatorTypeForFileState, ProgressIndicatorTypes } from '../../../../utils/utils';
1616

1717
export type AudioAttachmentUploadPreviewProps<CustomLocalMetadata = Record<string, unknown>> =
1818
UploadAttachmentPreviewProps<
1919
LocalAudioAttachment<CustomLocalMetadata> | LocalVoiceRecordingAttachment<CustomLocalMetadata>
20-
> & {
21-
/**
22-
* The audio attachment config
23-
*
24-
* @deprecated This is deprecated and will be removed in the future.
25-
*/
26-
audioAttachmentConfig: AudioConfig;
27-
/**
28-
* Callback to be called when the audio is loaded
29-
* @deprecated This is deprecated and will be removed in the future.
30-
*/
31-
onLoad: (index: string, duration: number) => void;
32-
/**
33-
* Callback to be called when the audio is played or paused
34-
* @deprecated This is deprecated and will be removed in the future.
35-
*/
36-
onPlayPause: (index: string, pausedStatus?: boolean) => void;
37-
/**
38-
* Callback to be called when the audio progresses
39-
* @deprecated This is deprecated and will be removed in the future.
40-
*/
41-
onProgress: (index: string, progress: number) => void;
42-
};
20+
>;
4321

4422
export const AudioAttachmentUploadPreview = ({
4523
attachment,
46-
audioAttachmentConfig,
4724
handleRetry,
4825
removeAttachments,
49-
onLoad,
50-
onPlayPause,
51-
onProgress,
5226
}: AudioAttachmentUploadPreviewProps) => {
5327
const { enableOfflineSupport } = useChatContext();
5428
const indicatorType = getIndicatorTypeForFileState(
@@ -69,9 +43,8 @@ export const AudioAttachmentUploadPreview = ({
6943
...attachment,
7044
asset_url: assetUrl,
7145
id: attachment.localMetadata.id,
72-
...audioAttachmentConfig,
7346
}),
74-
[attachment, assetUrl, audioAttachmentConfig],
47+
[attachment, assetUrl],
7548
);
7649

7750
const onRetryHandler = useCallback(() => {
@@ -93,9 +66,6 @@ export const AudioAttachmentUploadPreview = ({
9366
hideProgressBar={true}
9467
isPreview={true}
9568
item={finalAttachment}
96-
onLoad={onLoad}
97-
onPlayPause={onPlayPause}
98-
onProgress={onProgress}
9969
showSpeedSettings={false}
10070
titleMaxLength={12}
10171
/>

0 commit comments

Comments
 (0)