variable isAutoDownloadEnable name and handleMediaDownload getExtension

This commit is contained in:
Reinaldo Neto 2023-06-07 12:36:30 -03:00
parent c244dd4906
commit 6f3dc60994
2 changed files with 19 additions and 23 deletions

View File

@ -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 () => {

View File

@ -77,7 +77,6 @@ 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';
@ -93,8 +92,6 @@ const getExtension = (type: MediaTypes, mimeType?: string) => {
}
return extension;
};
return extensionFromMime();
};
const ensureDirAsync = async (dir: string, intermediates = true): Promise<void> => {
const info = await FileSystem.getInfoAsync(dir);