variable isAutoDownloadEnable name and handleMediaDownload getExtension
This commit is contained in:
parent
c244dd4906
commit
6f3dc60994
|
@ -178,13 +178,12 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
|||
try {
|
||||
if (url) {
|
||||
const isCurrentUserAuthor = author?._id === user.id;
|
||||
const autoDownload = fetchAutoDownloadEnabled('audioPreferenceDownload');
|
||||
if (autoDownload || isCurrentUserAuthor) {
|
||||
await this.startDownload();
|
||||
const isAutoDownloadEnabled = fetchAutoDownloadEnabled('audioPreferenceDownload');
|
||||
if (isAutoDownloadEnabled || isCurrentUserAuthor) {
|
||||
await this.handleDownload();
|
||||
return;
|
||||
}
|
||||
|
||||
// MediaDownloadOption.NEVER or MediaDownloadOption.WIFI and the mobile is using mobile data
|
||||
return this.setState({ loading: false, cached: false });
|
||||
}
|
||||
} catch {
|
||||
|
@ -286,7 +285,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
|||
this.setState({ paused: !paused }, this.playPause);
|
||||
};
|
||||
|
||||
startDownload = async () => {
|
||||
handleDownload = async () => {
|
||||
const { messageId } = this.props;
|
||||
// @ts-ignore can't use declare to type this
|
||||
const { user } = this.context;
|
||||
|
@ -311,7 +310,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
|||
|
||||
onPress = () => {
|
||||
const { cached } = this.state;
|
||||
return cached ? this.togglePlayPause() : this.startDownload();
|
||||
return cached ? this.togglePlayPause() : this.handleDownload();
|
||||
};
|
||||
|
||||
playPause = async () => {
|
||||
|
|
|
@ -77,23 +77,20 @@ const getExtension = (type: MediaTypes, mimeType?: string) => {
|
|||
if (!mimeType) {
|
||||
return defaultType[type];
|
||||
}
|
||||
const extensionFromMime = () => {
|
||||
// The library is returning mpag instead of mp3 for audio/mpeg
|
||||
if (mimeType === 'audio/mpeg') {
|
||||
return 'mp3';
|
||||
}
|
||||
// For older audios the server is returning the type audio/aac and we can't play it as mp3
|
||||
if (mimeType === 'audio/aac') {
|
||||
return 'm4a';
|
||||
}
|
||||
const extension = mime.extension(mimeType);
|
||||
// The mime.extension can return false when there aren't any extension
|
||||
if (!extension) {
|
||||
return defaultType[type];
|
||||
}
|
||||
return extension;
|
||||
};
|
||||
return extensionFromMime();
|
||||
// The library is returning mpag instead of mp3 for audio/mpeg
|
||||
if (mimeType === 'audio/mpeg') {
|
||||
return 'mp3';
|
||||
}
|
||||
// For older audios the server is returning the type audio/aac and we can't play it as mp3
|
||||
if (mimeType === 'audio/aac') {
|
||||
return 'm4a';
|
||||
}
|
||||
const extension = mime.extension(mimeType);
|
||||
// The mime.extension can return false when there aren't any extension
|
||||
if (!extension) {
|
||||
return defaultType[type];
|
||||
}
|
||||
return extension;
|
||||
};
|
||||
|
||||
const ensureDirAsync = async (dir: string, intermediates = true): Promise<void> => {
|
||||
|
|
Loading…
Reference in New Issue