2017-12-02 13:19:58 +00:00
|
|
|
import React from 'react';
|
2022-03-23 14:49:45 +00:00
|
|
|
import { StyleProp, StyleSheet, Text, TextStyle, View } from 'react-native';
|
2022-08-08 21:02:08 +00:00
|
|
|
import { Audio, AVPlaybackStatus, InterruptionModeAndroid, InterruptionModeIOS } from 'expo-av';
|
2019-10-04 13:38:35 +00:00
|
|
|
import Slider from '@react-native-community/slider';
|
2018-09-11 16:32:52 +00:00
|
|
|
import moment from 'moment';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2020-05-08 12:55:26 +00:00
|
|
|
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
|
2022-04-01 21:52:38 +00:00
|
|
|
import { Sound } from 'expo-av/build/Audio/Sound';
|
2018-09-11 16:32:52 +00:00
|
|
|
|
2020-04-30 20:05:59 +00:00
|
|
|
import Touchable from './Touchable';
|
2019-08-27 12:25:38 +00:00
|
|
|
import Markdown from '../markdown';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../CustomIcon';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../../views/Styles';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { isAndroid, isIOS } from '../../lib/methods/helpers';
|
2020-04-30 20:05:59 +00:00
|
|
|
import MessageContext from './Context';
|
2020-04-30 18:54:27 +00:00
|
|
|
import ActivityIndicator from '../ActivityIndicator';
|
2020-06-17 17:35:58 +00:00
|
|
|
import { withDimensions } from '../../dimensions';
|
2022-02-17 15:27:01 +00:00
|
|
|
import { TGetCustomEmoji } from '../../definitions/IEmoji';
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
import { IAttachment, IUserMessage } from '../../definitions';
|
|
|
|
import { TSupportedThemes, useTheme } from '../../theme';
|
|
|
|
import { downloadMediaFile, getMediaCache } from '../../lib/methods/handleMediaDownload';
|
2022-11-16 13:40:45 +00:00
|
|
|
import EventEmitter from '../../lib/methods/helpers/events';
|
|
|
|
import { PAUSE_AUDIO } from './constants';
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
import { fetchAutoDownloadEnabled } from '../../lib/methods/autoDownloadPreference';
|
2020-04-30 18:54:27 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IButton {
|
|
|
|
loading: boolean;
|
|
|
|
paused: boolean;
|
2022-03-21 20:44:06 +00:00
|
|
|
disabled?: boolean;
|
2022-04-01 21:52:38 +00:00
|
|
|
onPress: () => void;
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
cached: boolean;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IMessageAudioProps {
|
2022-03-21 20:44:06 +00:00
|
|
|
file: IAttachment;
|
|
|
|
isReply?: boolean;
|
|
|
|
style?: StyleProp<TextStyle>[];
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-02-17 15:27:01 +00:00
|
|
|
getCustomEmoji: TGetCustomEmoji;
|
2022-01-17 16:10:39 +00:00
|
|
|
scale?: number;
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
author?: IUserMessage;
|
2023-08-14 20:22:46 +00:00
|
|
|
msg?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IMessageAudioState {
|
|
|
|
loading: boolean;
|
|
|
|
currentTime: number;
|
|
|
|
duration: number;
|
|
|
|
paused: boolean;
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
cached: boolean;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 18:54:27 +00:00
|
|
|
const mode = {
|
|
|
|
allowsRecordingIOS: false,
|
|
|
|
playsInSilentModeIOS: true,
|
2021-09-21 14:47:00 +00:00
|
|
|
staysActiveInBackground: true,
|
2020-04-30 18:54:27 +00:00
|
|
|
shouldDuckAndroid: true,
|
|
|
|
playThroughEarpieceAndroid: false,
|
2022-08-08 21:02:08 +00:00
|
|
|
interruptionModeIOS: InterruptionModeIOS.DoNotMix,
|
|
|
|
interruptionModeAndroid: InterruptionModeAndroid.DoNotMix
|
2020-04-30 18:54:27 +00:00
|
|
|
};
|
2017-12-28 17:40:10 +00:00
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
audioContainer: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
2018-09-11 16:32:52 +00:00
|
|
|
height: 56,
|
2019-03-29 19:36:07 +00:00
|
|
|
borderWidth: 1,
|
2018-09-11 16:32:52 +00:00
|
|
|
borderRadius: 4,
|
2019-03-29 19:36:07 +00:00
|
|
|
marginBottom: 6
|
2017-12-02 13:19:58 +00:00
|
|
|
},
|
|
|
|
playPauseButton: {
|
2019-04-24 18:36:29 +00:00
|
|
|
marginHorizontal: 10,
|
2017-12-02 13:19:58 +00:00
|
|
|
alignItems: 'center',
|
|
|
|
backgroundColor: 'transparent'
|
|
|
|
},
|
2020-04-30 18:54:27 +00:00
|
|
|
audioLoading: {
|
|
|
|
marginHorizontal: 8
|
|
|
|
},
|
2018-09-11 16:32:52 +00:00
|
|
|
slider: {
|
2019-04-24 18:36:29 +00:00
|
|
|
flex: 1
|
2017-12-02 13:19:58 +00:00
|
|
|
},
|
|
|
|
duration: {
|
2019-04-24 18:36:29 +00:00
|
|
|
marginHorizontal: 12,
|
2018-09-11 16:32:52 +00:00
|
|
|
fontSize: 14,
|
2019-03-29 19:36:07 +00:00
|
|
|
...sharedStyles.textRegular
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const formatTime = (seconds: number) => moment.utc(seconds * 1000).format('mm:ss');
|
|
|
|
|
|
|
|
const BUTTON_HIT_SLOP = { top: 12, right: 12, bottom: 12, left: 12 };
|
|
|
|
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
const Button = React.memo(({ loading, paused, onPress, disabled, cached }: IButton) => {
|
|
|
|
const { colors } = useTheme();
|
|
|
|
|
|
|
|
let customIconName: 'arrow-down-circle' | 'play-filled' | 'pause-filled' = 'arrow-down-circle';
|
|
|
|
if (cached) {
|
|
|
|
customIconName = paused ? 'play-filled' : 'pause-filled';
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Touchable
|
|
|
|
style={styles.playPauseButton}
|
|
|
|
disabled={disabled}
|
|
|
|
onPress={onPress}
|
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
|
|
|
background={Touchable.SelectableBackgroundBorderless()}
|
|
|
|
>
|
|
|
|
{loading ? (
|
|
|
|
<ActivityIndicator style={[styles.playPauseButton, styles.audioLoading]} />
|
|
|
|
) : (
|
|
|
|
<CustomIcon name={customIconName} size={36} color={disabled ? colors.tintDisabled : colors.tintColor} />
|
|
|
|
)}
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
});
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
Button.displayName = 'MessageAudioButton';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioState> {
|
2020-04-30 20:05:59 +00:00
|
|
|
static contextType = MessageContext;
|
2023-08-18 17:48:33 +00:00
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
private sound: Sound;
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
constructor(props: IMessageAudioProps) {
|
2017-12-02 13:19:58 +00:00
|
|
|
super(props);
|
|
|
|
this.state = {
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
loading: true,
|
2017-12-02 13:19:58 +00:00
|
|
|
currentTime: 0,
|
|
|
|
duration: 0,
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
paused: true,
|
|
|
|
cached: false
|
2017-12-02 13:19:58 +00:00
|
|
|
};
|
2020-04-30 18:54:27 +00:00
|
|
|
|
|
|
|
this.sound = new Audio.Sound();
|
|
|
|
this.sound.setOnPlaybackStatusUpdate(this.onPlaybackStatusUpdate);
|
|
|
|
}
|
|
|
|
|
2022-11-16 13:40:45 +00:00
|
|
|
pauseSound = () => {
|
|
|
|
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
|
|
|
|
this.togglePlayPause();
|
|
|
|
};
|
|
|
|
|
2020-04-30 18:54:27 +00:00
|
|
|
async componentDidMount() {
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
const { file, isReply } = this.props;
|
|
|
|
const cachedAudioResult = await getMediaCache({
|
|
|
|
type: 'audio',
|
|
|
|
mimeType: file.audio_type,
|
|
|
|
urlToCache: this.getUrl()
|
|
|
|
});
|
|
|
|
if (cachedAudioResult?.exists) {
|
|
|
|
await this.sound.loadAsync({ uri: cachedAudioResult.uri });
|
|
|
|
this.setState({ loading: false, cached: true });
|
|
|
|
return;
|
2020-05-08 17:07:58 +00:00
|
|
|
}
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
if (isReply) {
|
|
|
|
this.setState({ loading: false });
|
|
|
|
return;
|
2020-04-30 18:54:27 +00:00
|
|
|
}
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
await this.handleAutoDownload();
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
shouldComponentUpdate(nextProps: IMessageAudioProps, nextState: IMessageAudioState) {
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
const { currentTime, duration, paused, loading, cached } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { file, theme } = this.props;
|
2019-12-04 16:39:53 +00:00
|
|
|
if (nextProps.theme !== theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextState.currentTime !== currentTime) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextState.duration !== duration) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextState.paused !== paused) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextProps.file, file)) {
|
2018-12-21 10:55:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-04-30 18:54:27 +00:00
|
|
|
if (nextState.loading !== loading) {
|
|
|
|
return true;
|
|
|
|
}
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
if (nextState.cached !== cached) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-08 12:55:26 +00:00
|
|
|
componentDidUpdate() {
|
|
|
|
const { paused } = this.state;
|
|
|
|
if (paused) {
|
|
|
|
deactivateKeepAwake();
|
|
|
|
} else {
|
|
|
|
activateKeepAwake();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 18:54:27 +00:00
|
|
|
async componentWillUnmount() {
|
2022-11-16 13:40:45 +00:00
|
|
|
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
|
2020-04-30 18:54:27 +00:00
|
|
|
try {
|
|
|
|
await this.sound.stopAsync();
|
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
getUrl = () => {
|
|
|
|
const { file } = this.props;
|
|
|
|
// @ts-ignore can't use declare to type this
|
|
|
|
const { baseUrl } = this.context;
|
|
|
|
|
|
|
|
let url = file.audio_url;
|
|
|
|
if (url && !url.startsWith('http')) {
|
|
|
|
url = `${baseUrl}${file.audio_url}`;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
|
|
|
handleAutoDownload = async () => {
|
|
|
|
const { author } = this.props;
|
|
|
|
// @ts-ignore can't use declare to type this
|
|
|
|
const { user } = this.context;
|
|
|
|
const url = this.getUrl();
|
|
|
|
try {
|
|
|
|
if (url) {
|
|
|
|
const isCurrentUserAuthor = author?._id === user.id;
|
|
|
|
const isAutoDownloadEnabled = fetchAutoDownloadEnabled('audioPreferenceDownload');
|
|
|
|
if (isAutoDownloadEnabled || isCurrentUserAuthor) {
|
|
|
|
await this.handleDownload();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ loading: false, cached: false });
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
onPlaybackStatusUpdate = (status: AVPlaybackStatus) => {
|
2020-04-30 18:54:27 +00:00
|
|
|
if (status) {
|
|
|
|
this.onLoad(status);
|
|
|
|
this.onProgress(status);
|
|
|
|
this.onEnd(status);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-04-30 18:54:27 +00:00
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
onLoad = (data: AVPlaybackStatus) => {
|
|
|
|
if (data.isLoaded && data.durationMillis) {
|
|
|
|
const duration = data.durationMillis / 1000;
|
|
|
|
this.setState({ duration: duration > 0 ? duration : 0 });
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
onProgress = (data: AVPlaybackStatus) => {
|
|
|
|
if (data.isLoaded) {
|
|
|
|
const { duration } = this.state;
|
|
|
|
const currentTime = data.positionMillis / 1000;
|
|
|
|
if (currentTime <= duration) {
|
|
|
|
this.setState({ currentTime });
|
|
|
|
}
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
onEnd = async (data: AVPlaybackStatus) => {
|
|
|
|
if (data.isLoaded) {
|
|
|
|
if (data.didJustFinish) {
|
|
|
|
try {
|
|
|
|
await this.sound.stopAsync();
|
|
|
|
this.setState({ paused: true, currentTime: 0 });
|
2022-11-16 13:40:45 +00:00
|
|
|
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
|
2022-04-01 21:52:38 +00:00
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
2020-04-30 18:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
get duration() {
|
2020-04-30 18:54:27 +00:00
|
|
|
const { currentTime, duration } = this.state;
|
|
|
|
return formatTime(currentTime || duration);
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 18:36:29 +00:00
|
|
|
togglePlayPause = () => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { paused } = this.state;
|
2020-04-30 18:54:27 +00:00
|
|
|
this.setState({ paused: !paused }, this.playPause);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-12-02 13:19:58 +00:00
|
|
|
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
handleDownload = async () => {
|
|
|
|
const { file } = this.props;
|
|
|
|
// @ts-ignore can't use declare to type this
|
|
|
|
const { user } = this.context;
|
|
|
|
this.setState({ loading: true });
|
|
|
|
try {
|
|
|
|
const url = this.getUrl();
|
|
|
|
if (url) {
|
|
|
|
const audio = await downloadMediaFile({
|
|
|
|
downloadUrl: `${url}?rc_uid=${user.id}&rc_token=${user.token}`,
|
|
|
|
type: 'audio',
|
|
|
|
mimeType: file.audio_type
|
|
|
|
});
|
|
|
|
await this.sound.loadAsync({ uri: audio });
|
|
|
|
this.setState({ loading: false, cached: true });
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
this.setState({ loading: false, cached: false });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
onPress = () => {
|
|
|
|
const { cached, loading } = this.state;
|
|
|
|
if (loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cached) {
|
|
|
|
this.togglePlayPause();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.handleDownload();
|
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
playPause = async () => {
|
2020-04-30 18:54:27 +00:00
|
|
|
const { paused } = this.state;
|
|
|
|
try {
|
|
|
|
if (paused) {
|
|
|
|
await this.sound.pauseAsync();
|
2022-11-16 13:40:45 +00:00
|
|
|
EventEmitter.removeListener(PAUSE_AUDIO, this.pauseSound);
|
2020-04-30 18:54:27 +00:00
|
|
|
} else {
|
2022-11-16 13:40:45 +00:00
|
|
|
EventEmitter.emit(PAUSE_AUDIO);
|
|
|
|
EventEmitter.addEventListener(PAUSE_AUDIO, this.pauseSound);
|
2020-07-06 19:23:46 +00:00
|
|
|
await Audio.setAudioModeAsync(mode);
|
2020-04-30 18:54:27 +00:00
|
|
|
await this.sound.playAsync();
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-04-30 18:54:27 +00:00
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
onValueChange = async (value: number) => {
|
2020-04-30 18:54:27 +00:00
|
|
|
try {
|
|
|
|
this.setState({ currentTime: value });
|
|
|
|
await this.sound.setPositionAsync(value * 1000);
|
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
render() {
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
const { loading, paused, currentTime, duration, cached } = this.state;
|
2023-08-14 20:22:46 +00:00
|
|
|
const { msg, getCustomEmoji, theme, scale, isReply, style } = this.props;
|
2023-05-18 21:09:33 +00:00
|
|
|
// @ts-ignore can't use declare to type this
|
2020-04-30 20:05:59 +00:00
|
|
|
const { baseUrl, user } = this.context;
|
2018-09-14 19:39:52 +00:00
|
|
|
|
|
|
|
if (!baseUrl) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-04-12 16:27:05 +00:00
|
|
|
let thumbColor;
|
|
|
|
if (isAndroid && isReply) {
|
|
|
|
thumbColor = themes[theme].tintDisabled;
|
|
|
|
} else if (isAndroid) {
|
|
|
|
thumbColor = themes[theme].tintColor;
|
|
|
|
}
|
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2023-08-18 17:48:33 +00:00
|
|
|
<Markdown msg={msg} style={[isReply && style]} username={user.username} getCustomEmoji={getCustomEmoji} theme={theme} />
|
2019-12-04 16:39:53 +00:00
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.audioContainer,
|
2020-06-15 14:00:46 +00:00
|
|
|
{ backgroundColor: themes[theme].chatComponentBackground, borderColor: themes[theme].borderColor }
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>
|
feat: add media auto-download (#5076)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* fix blur is hiding the file description
* avoid download unsupported video
* return void when it is loading the audio
2023-08-07 14:02:30 +00:00
|
|
|
<Button disabled={isReply} loading={loading} paused={paused} cached={cached} onPress={this.onPress} />
|
2018-09-11 16:32:52 +00:00
|
|
|
<Slider
|
2022-03-21 20:44:06 +00:00
|
|
|
disabled={isReply}
|
2018-09-11 16:32:52 +00:00
|
|
|
style={styles.slider}
|
2018-09-25 19:28:42 +00:00
|
|
|
value={currentTime}
|
|
|
|
maximumValue={duration}
|
2018-09-11 16:32:52 +00:00
|
|
|
minimumValue={0}
|
2022-04-12 16:27:05 +00:00
|
|
|
thumbTintColor={thumbColor}
|
2019-12-04 16:39:53 +00:00
|
|
|
minimumTrackTintColor={themes[theme].tintColor}
|
|
|
|
maximumTrackTintColor={themes[theme].auxiliaryText}
|
2019-05-20 20:43:50 +00:00
|
|
|
onValueChange={this.onValueChange}
|
2022-03-21 20:44:06 +00:00
|
|
|
thumbImage={isIOS ? { uri: 'audio_thumb', scale } : undefined}
|
2018-09-11 16:32:52 +00:00
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.duration, { color: themes[theme].auxiliaryText }]}>{this.duration}</Text>
|
2019-05-20 20:43:50 +00:00
|
|
|
</View>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2017-12-02 13:19:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2020-06-17 17:35:58 +00:00
|
|
|
export default withDimensions(MessageAudio);
|