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 { try {
if (url) { if (url) {
const isCurrentUserAuthor = author?._id === user.id; const isCurrentUserAuthor = author?._id === user.id;
const autoDownload = fetchAutoDownloadEnabled('audioPreferenceDownload'); const isAutoDownloadEnabled = fetchAutoDownloadEnabled('audioPreferenceDownload');
if (autoDownload || isCurrentUserAuthor) { if (isAutoDownloadEnabled || isCurrentUserAuthor) {
await this.startDownload(); await this.handleDownload();
return; return;
} }
// MediaDownloadOption.NEVER or MediaDownloadOption.WIFI and the mobile is using mobile data
return this.setState({ loading: false, cached: false }); return this.setState({ loading: false, cached: false });
} }
} catch { } catch {
@ -286,7 +285,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
this.setState({ paused: !paused }, this.playPause); this.setState({ paused: !paused }, this.playPause);
}; };
startDownload = async () => { handleDownload = async () => {
const { messageId } = this.props; const { messageId } = this.props;
// @ts-ignore can't use declare to type this // @ts-ignore can't use declare to type this
const { user } = this.context; const { user } = this.context;
@ -311,7 +310,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
onPress = () => { onPress = () => {
const { cached } = this.state; const { cached } = this.state;
return cached ? this.togglePlayPause() : this.startDownload(); return cached ? this.togglePlayPause() : this.handleDownload();
}; };
playPause = async () => { playPause = async () => {

View File

@ -77,7 +77,6 @@ const getExtension = (type: MediaTypes, mimeType?: string) => {
if (!mimeType) { if (!mimeType) {
return defaultType[type]; return defaultType[type];
} }
const extensionFromMime = () => {
// The library is returning mpag instead of mp3 for audio/mpeg // The library is returning mpag instead of mp3 for audio/mpeg
if (mimeType === 'audio/mpeg') { if (mimeType === 'audio/mpeg') {
return 'mp3'; return 'mp3';
@ -92,8 +91,6 @@ const getExtension = (type: MediaTypes, mimeType?: string) => {
return defaultType[type]; return defaultType[type];
} }
return extension; return extension;
};
return extensionFromMime();
}; };
const ensureDirAsync = async (dir: string, intermediates = true): Promise<void> => { const ensureDirAsync = async (dir: string, intermediates = true): Promise<void> => {