From a92d88c99d6bcc66d4b0dc884fe76f33fe985767 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Fri, 30 Jun 2023 11:26:46 -0300 Subject: [PATCH] change the name to netInfoState and Local_document_directory --- app/actions/app.ts | 10 +++++----- app/containers/ImageViewer/ImageComponent.ts | 4 ++-- app/containers/message/Video.tsx | 4 ++-- app/lib/methods/autoDownloadPreference.ts | 8 ++++---- app/lib/methods/handleMediaDownload.ts | 6 +++--- app/lib/methods/helpers/formatAttachmentUrl.ts | 4 ++-- app/lib/methods/userPreferences.ts | 4 ++-- app/lib/store/internetStateMiddleware.ts | 4 ++-- app/reducers/app.ts | 6 +++--- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/actions/app.ts b/app/actions/app.ts index bafcc46ec..5969338a2 100644 --- a/app/actions/app.ts +++ b/app/actions/app.ts @@ -17,11 +17,11 @@ interface ISetNotificationPresenceCap extends Action { show: boolean; } -interface ISetInternetType extends Action { - internetType: NetInfoStateType; +interface ISetNetInfoState extends Action { + netInfoState: NetInfoStateType; } -export type TActionApp = IAppStart & ISetMasterDetail & ISetNotificationPresenceCap & ISetInternetType; +export type TActionApp = IAppStart & ISetMasterDetail & ISetNotificationPresenceCap & ISetNetInfoState; interface Params { root: RootEnum; @@ -68,9 +68,9 @@ export function setNotificationPresenceCap(show: boolean): ISetNotificationPrese }; } -export function setInternetType(internetType: NetInfoStateType): ISetInternetType { +export function setNetInfoState(netInfoState: NetInfoStateType): ISetNetInfoState { return { type: APP.SET_INTERNET_TYPE, - internetType + netInfoState }; } diff --git a/app/containers/ImageViewer/ImageComponent.ts b/app/containers/ImageViewer/ImageComponent.ts index b9f3831ad..ad307ee44 100644 --- a/app/containers/ImageViewer/ImageComponent.ts +++ b/app/containers/ImageViewer/ImageComponent.ts @@ -3,7 +3,7 @@ import { Image } from 'react-native'; import { FastImageProps } from 'react-native-fast-image'; import { types } from './types'; -import { LOCAL_DOCUMENT_PATH } from '../../lib/methods/handleMediaDownload'; +import { LOCAL_DOCUMENT_DIRECTORY } from '../../lib/methods/handleMediaDownload'; export function ImageComponent({ type, @@ -13,7 +13,7 @@ export function ImageComponent({ uri: string; }): React.ComponentType | FastImageProps> { let Component; - if (type === types.REACT_NATIVE_IMAGE || uri.startsWith(LOCAL_DOCUMENT_PATH)) { + if (type === types.REACT_NATIVE_IMAGE || (LOCAL_DOCUMENT_DIRECTORY && uri.startsWith(LOCAL_DOCUMENT_DIRECTORY))) { const { Image } = require('react-native'); Component = Image; } else { diff --git a/app/containers/message/Video.tsx b/app/containers/message/Video.tsx index eb3c7a9ef..75afd684d 100644 --- a/app/containers/message/Video.tsx +++ b/app/containers/message/Video.tsx @@ -18,7 +18,7 @@ import { TGetCustomEmoji } from '../../definitions/IEmoji'; import { useTheme } from '../../theme'; import { formatAttachmentUrl } from '../../lib/methods/helpers/formatAttachmentUrl'; import { - LOCAL_DOCUMENT_PATH, + LOCAL_DOCUMENT_DIRECTORY, cancelDownload, downloadMediaFile, isDownloadActive, @@ -139,7 +139,7 @@ const Video = React.memo( const onPress = async () => { if (file.video_type && isTypeSupported(file.video_type) && showAttachment) { - if (!videoCached.video_url?.startsWith(LOCAL_DOCUMENT_PATH) && !loading) { + if (LOCAL_DOCUMENT_DIRECTORY && !videoCached.video_url?.startsWith(LOCAL_DOCUMENT_DIRECTORY) && !loading) { // Keep the video downloading while showing the video buffering handleDownload(); } diff --git a/app/lib/methods/autoDownloadPreference.ts b/app/lib/methods/autoDownloadPreference.ts index 104b9cbe0..5c6cd89e5 100644 --- a/app/lib/methods/autoDownloadPreference.ts +++ b/app/lib/methods/autoDownloadPreference.ts @@ -12,8 +12,8 @@ import { store } from '../store/auxStore'; type TMediaType = typeof IMAGES_PREFERENCE_DOWNLOAD | typeof AUDIO_PREFERENCE_DOWNLOAD | typeof VIDEO_PREFERENCE_DOWNLOAD; export const fetchAutoDownloadEnabled = (mediaType: TMediaType) => { - const { internetType } = store.getState().app; - const mediaDownloadPreference = userPreferences.getString(mediaType); + const { netInfoState } = store.getState().app; + const mediaDownloadPreference = userPreferences.getString(mediaType) as MediaDownloadOption; let defaultValueByMediaType = false; if (mediaDownloadPreference === null) { @@ -23,12 +23,12 @@ export const fetchAutoDownloadEnabled = (mediaType: TMediaType) => { } if (mediaType === 'audioPreferenceDownload' || mediaType === 'videoPreferenceDownload') { // The same as 'wifi' - defaultValueByMediaType = internetType === NetInfoStateType.wifi; + defaultValueByMediaType = netInfoState === NetInfoStateType.wifi; } } return ( - (mediaDownloadPreference === 'wifi' && internetType === NetInfoStateType.wifi) || + (mediaDownloadPreference === 'wifi' && netInfoState === NetInfoStateType.wifi) || mediaDownloadPreference === 'wifi_mobile_data' || defaultValueByMediaType ); diff --git a/app/lib/methods/handleMediaDownload.ts b/app/lib/methods/handleMediaDownload.ts index bcf0371af..b4983d495 100644 --- a/app/lib/methods/handleMediaDownload.ts +++ b/app/lib/methods/handleMediaDownload.ts @@ -64,7 +64,7 @@ export function downloadMediaFile({ }); } -export const LOCAL_DOCUMENT_PATH = `${FileSystem.documentDirectory}`; +export const LOCAL_DOCUMENT_DIRECTORY = FileSystem.documentDirectory; const sanitizeString = (value: string) => { const urlWithoutQueryString = value.split('?')[0]; @@ -113,7 +113,7 @@ export const searchMediaFileAsync = async ({ try { const serverUrl = store.getState().server.server; const serverUrlParsed = serverUrlParsedAsPath(serverUrl); - const folderPath = `${LOCAL_DOCUMENT_PATH}${serverUrlParsed}${typeString[type]}`; + const folderPath = `${LOCAL_DOCUMENT_DIRECTORY}${serverUrlParsed}${typeString[type]}`; const fileUrlSanitized = sanitizeString(urlToCache); const filename = `${fileUrlSanitized}.${getExtension(type, mimeType)}`; const filePath = `${folderPath}${filename}`; @@ -129,7 +129,7 @@ export const searchMediaFileAsync = async ({ export const deleteMediaFiles = async (serverUrl: string): Promise => { try { const serverUrlParsed = serverUrlParsedAsPath(serverUrl); - const path = `${LOCAL_DOCUMENT_PATH}${serverUrlParsed}`; + const path = `${LOCAL_DOCUMENT_DIRECTORY}${serverUrlParsed}`; await FileSystem.deleteAsync(path, { idempotent: true }); } catch (error) { log(error); diff --git a/app/lib/methods/helpers/formatAttachmentUrl.ts b/app/lib/methods/helpers/formatAttachmentUrl.ts index b9102b8c6..b7a652fd5 100644 --- a/app/lib/methods/helpers/formatAttachmentUrl.ts +++ b/app/lib/methods/helpers/formatAttachmentUrl.ts @@ -1,7 +1,7 @@ -import { LOCAL_DOCUMENT_PATH } from '../handleMediaDownload'; +import { LOCAL_DOCUMENT_DIRECTORY } from '../handleMediaDownload'; export const formatAttachmentUrl = (attachmentUrl: string | undefined, userId: string, token: string, server: string): string => { - if (attachmentUrl?.startsWith(LOCAL_DOCUMENT_PATH)) { + if (LOCAL_DOCUMENT_DIRECTORY && attachmentUrl?.startsWith(LOCAL_DOCUMENT_DIRECTORY)) { return attachmentUrl; } if (attachmentUrl && attachmentUrl.startsWith('http')) { diff --git a/app/lib/methods/userPreferences.ts b/app/lib/methods/userPreferences.ts index 18c3800f9..879566454 100644 --- a/app/lib/methods/userPreferences.ts +++ b/app/lib/methods/userPreferences.ts @@ -14,9 +14,9 @@ class UserPreferences { this.mmkv = MMKV; } - getString(key: string) { + getString(key: string) { try { - return (this.mmkv.getString(key) as T) ?? null; + return this.mmkv.getString(key) ?? null; } catch { return null; } diff --git a/app/lib/store/internetStateMiddleware.ts b/app/lib/store/internetStateMiddleware.ts index 430ca8403..150e3d87e 100644 --- a/app/lib/store/internetStateMiddleware.ts +++ b/app/lib/store/internetStateMiddleware.ts @@ -1,6 +1,6 @@ import NetInfo, { NetInfoState, NetInfoStateType } from '@react-native-community/netinfo'; -import { setInternetType } from '../../actions/app'; +import { setNetInfoState } from '../../actions/app'; export default () => (createStore: any) => @@ -9,7 +9,7 @@ export default () => let currentType: NetInfoStateType | undefined; const handleInternetStateChange = (nextState: NetInfoState) => { if (nextState.type !== currentType) { - store.dispatch(setInternetType(nextState.type)); + store.dispatch(setNetInfoState(nextState.type)); currentType = nextState.type; } }; diff --git a/app/reducers/app.ts b/app/reducers/app.ts index 83b9af389..f13100be5 100644 --- a/app/reducers/app.ts +++ b/app/reducers/app.ts @@ -12,7 +12,7 @@ export interface IApp { foreground: boolean; background: boolean; notificationPresenceCap: boolean; - internetType?: NetInfoStateType; + netInfoState?: NetInfoStateType | null; } export const initialState: IApp = { @@ -23,7 +23,7 @@ export const initialState: IApp = { foreground: true, background: false, notificationPresenceCap: false, - internetType: undefined + netInfoState: null }; export default function app(state = initialState, action: TActionApp): IApp { @@ -69,7 +69,7 @@ export default function app(state = initialState, action: TActionApp): IApp { case APP.SET_INTERNET_TYPE: return { ...state, - internetType: action.internetType + netInfoState: action.netInfoState }; default: return state;