change the name to netInfoState and Local_document_directory
This commit is contained in:
parent
e0b86c0aa6
commit
a92d88c99d
|
@ -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
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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<Partial<Image> | 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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<MediaDownloadOption>(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
|
||||
);
|
||||
|
|
|
@ -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<void> => {
|
||||
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);
|
||||
|
|
|
@ -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')) {
|
||||
|
|
|
@ -14,9 +14,9 @@ class UserPreferences {
|
|||
this.mmkv = MMKV;
|
||||
}
|
||||
|
||||
getString<T = string>(key: string) {
|
||||
getString(key: string) {
|
||||
try {
|
||||
return (this.mmkv.getString(key) as T) ?? null;
|
||||
return this.mmkv.getString(key) ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue