Skip to content

Commit 7c1bba3

Browse files
committed
fix: audio attachment issues
1 parent 21589ea commit 7c1bba3

File tree

5 files changed

+30
-32
lines changed

5 files changed

+30
-32
lines changed

package/src/components/Attachment/AudioAttachment.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { I18nManager, Pressable, StyleSheet, Text, View } from 'react-native';
44
import dayjs from 'dayjs';
55
import duration from 'dayjs/plugin/duration';
66

7+
import { AudioAttachment as StreamAudioAttachment } from 'stream-chat';
8+
79
import { useTheme } from '../../contexts';
810
import { useAudioPlayer } from '../../hooks/useAudioPlayer';
911
import { Audio, Pause, Play } from '../../icons';
@@ -22,19 +24,18 @@ import { WaveProgressBar } from '../ProgressControl/WaveProgressBar';
2224

2325
dayjs.extend(duration);
2426

25-
export type AudioAttachmentType = AudioConfig & {
26-
asset_url?: string;
27-
id: string;
28-
title?: string;
29-
type: 'audio' | 'voiceRecording';
30-
waveform_data?: number[];
31-
};
27+
export type AudioAttachmentType = AudioConfig &
28+
Pick<StreamAudioAttachment, 'waveform_data' | 'asset_url' | 'title'> & {
29+
id: string;
30+
type: 'audio' | 'voiceRecording';
31+
};
3232

3333
export type AudioAttachmentProps = {
3434
item: AudioAttachmentType;
3535
onLoad: (index: string, duration: number) => void;
3636
onPlayPause: (index: string, pausedStatus?: boolean) => void;
3737
onProgress: (index: string, progress: number) => void;
38+
titleMaxLength?: number;
3839
hideProgressBar?: boolean;
3940
showSpeedSettings?: boolean;
4041
testID?: string;
@@ -56,6 +57,7 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
5657
onProgress,
5758
showSpeedSettings = false,
5859
testID,
60+
titleMaxLength,
5961
} = props;
6062
const { changeAudioSpeed, pauseAudio, playAudio, seekAudio } = useAudioPlayer({ soundRef });
6163
const isExpoCLI = NativeHandlers.SDK === 'stream-chat-expo';
@@ -326,7 +328,9 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
326328
filenameText,
327329
]}
328330
>
329-
{getTrimmedAttachmentTitle(item.title)}
331+
{item.type === FileTypes.VoiceRecording
332+
? 'Recording'
333+
: getTrimmedAttachmentTitle(item.title, titleMaxLength)}
330334
</Text>
331335
<View style={styles.audioInfo}>
332336
<Text style={[styles.progressDurationText, { color: grey_dark }, progressDurationText]}>

package/src/components/Attachment/FileAttachmentGroup.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,9 @@ const FileAttachmentGroupWithContext = (props: FileAttachmentGroupPropsWithConte
111111
isSoundPackageAvailable() ? (
112112
<AudioAttachment
113113
item={{
114-
asset_url: file.asset_url,
115-
duration: file.duration,
114+
...file,
116115
id: index.toString(),
117-
paused: file.paused,
118-
progress: file.progress,
119-
title: file.title,
120116
type: file.type,
121-
waveform_data: file.waveform_data,
122117
}}
123118
onLoad={onLoad}
124119
onPlayPause={onPlayPause}

package/src/components/Channel/Channel.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
13021302
messageResponse = await doSendMessageRequest(channel?.cid || '', messageData, options);
13031303
} else if (channel) {
13041304
messageResponse = await channel.sendMessage(messageData, options);
1305-
console.log(messageResponse);
13061305
}
13071306

13081307
if (messageResponse.message) {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from 'react';
22

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

5-
import { LocalAudioAttachment, LocalVoiceRecordingAttachment } from 'stream-chat';
5+
import { FileReference, LocalAudioAttachment, LocalVoiceRecordingAttachment } from 'stream-chat';
66

77
import { AttachmentUploadProgressIndicator } from './AttachmentUploadProgressIndicator';
88
import { DismissAttachmentUpload } from './DismissAttachmentUpload';
@@ -39,11 +39,9 @@ export const AudioAttachmentUploadPreview = ({
3939

4040
const finalAttachment = useMemo(
4141
() => ({
42-
asset_url: attachment.asset_url,
42+
...attachment,
43+
asset_url: (attachment.localMetadata.file as FileReference).uri,
4344
id: attachment.localMetadata.id,
44-
title: attachment.title,
45-
type: attachment.type,
46-
waveform_data: attachment.waveform_data,
4745
...audioAttachmentConfig,
4846
}),
4947
[attachment, audioAttachmentConfig],
@@ -72,6 +70,7 @@ export const AudioAttachmentUploadPreview = ({
7270
onProgress={onProgress}
7371
showSpeedSettings={false}
7472
testID='audio-attachment-upload-preview'
73+
titleMaxLength={12}
7574
/>
7675
</AttachmentUploadProgressIndicator>
7776
<View style={styles.dismissWrapper}>
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { lookup } from 'mime-types';
1+
// Add dots in between the title if it is too long and then append the remaining last characters.
2+
// Eg: "This is a very long title" => "This is a very long ti...le"
3+
export const getTrimmedAttachmentTitle = (title?: string, maxLength?: number) => {
4+
const maxLengthValue = maxLength || 18;
5+
if (!title) return '';
26

3-
export const getTrimmedAttachmentTitle = (title?: string) => {
4-
if (!title) {
5-
return '';
6-
}
7+
const ellipsis = '...';
78

8-
const mimeType = lookup(title);
9-
if (mimeType) {
10-
const lastIndexOfDot = title.lastIndexOf('.');
11-
return title.length < 12 ? title : title.slice(0, 12) + '...' + title.slice(lastIndexOfDot);
12-
} else {
13-
// shorten title
14-
return title.length < 20 ? title : title.slice(0, 20) + '...';
9+
if (title.length <= maxLengthValue) {
10+
return title;
1511
}
12+
13+
const start = title.slice(0, maxLengthValue / 2);
14+
const end = title.slice(title.length - maxLengthValue / 2);
15+
16+
return `${start}${ellipsis}${end}`;
1617
};

0 commit comments

Comments
 (0)