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;
|
show: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ISetInternetType extends Action {
|
interface ISetNetInfoState extends Action {
|
||||||
internetType: NetInfoStateType;
|
netInfoState: NetInfoStateType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TActionApp = IAppStart & ISetMasterDetail & ISetNotificationPresenceCap & ISetInternetType;
|
export type TActionApp = IAppStart & ISetMasterDetail & ISetNotificationPresenceCap & ISetNetInfoState;
|
||||||
|
|
||||||
interface Params {
|
interface Params {
|
||||||
root: RootEnum;
|
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 {
|
return {
|
||||||
type: APP.SET_INTERNET_TYPE,
|
type: APP.SET_INTERNET_TYPE,
|
||||||
internetType
|
netInfoState
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Image } from 'react-native';
|
||||||
import { FastImageProps } from 'react-native-fast-image';
|
import { FastImageProps } from 'react-native-fast-image';
|
||||||
|
|
||||||
import { types } from './types';
|
import { types } from './types';
|
||||||
import { LOCAL_DOCUMENT_PATH } from '../../lib/methods/handleMediaDownload';
|
import { LOCAL_DOCUMENT_DIRECTORY } from '../../lib/methods/handleMediaDownload';
|
||||||
|
|
||||||
export function ImageComponent({
|
export function ImageComponent({
|
||||||
type,
|
type,
|
||||||
|
@ -13,7 +13,7 @@ export function ImageComponent({
|
||||||
uri: string;
|
uri: string;
|
||||||
}): React.ComponentType<Partial<Image> | FastImageProps> {
|
}): React.ComponentType<Partial<Image> | FastImageProps> {
|
||||||
let Component;
|
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');
|
const { Image } = require('react-native');
|
||||||
Component = Image;
|
Component = Image;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import { TGetCustomEmoji } from '../../definitions/IEmoji';
|
||||||
import { useTheme } from '../../theme';
|
import { useTheme } from '../../theme';
|
||||||
import { formatAttachmentUrl } from '../../lib/methods/helpers/formatAttachmentUrl';
|
import { formatAttachmentUrl } from '../../lib/methods/helpers/formatAttachmentUrl';
|
||||||
import {
|
import {
|
||||||
LOCAL_DOCUMENT_PATH,
|
LOCAL_DOCUMENT_DIRECTORY,
|
||||||
cancelDownload,
|
cancelDownload,
|
||||||
downloadMediaFile,
|
downloadMediaFile,
|
||||||
isDownloadActive,
|
isDownloadActive,
|
||||||
|
@ -139,7 +139,7 @@ const Video = React.memo(
|
||||||
|
|
||||||
const onPress = async () => {
|
const onPress = async () => {
|
||||||
if (file.video_type && isTypeSupported(file.video_type) && showAttachment) {
|
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
|
// Keep the video downloading while showing the video buffering
|
||||||
handleDownload();
|
handleDownload();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ import { store } from '../store/auxStore';
|
||||||
type TMediaType = typeof IMAGES_PREFERENCE_DOWNLOAD | typeof AUDIO_PREFERENCE_DOWNLOAD | typeof VIDEO_PREFERENCE_DOWNLOAD;
|
type TMediaType = typeof IMAGES_PREFERENCE_DOWNLOAD | typeof AUDIO_PREFERENCE_DOWNLOAD | typeof VIDEO_PREFERENCE_DOWNLOAD;
|
||||||
|
|
||||||
export const fetchAutoDownloadEnabled = (mediaType: TMediaType) => {
|
export const fetchAutoDownloadEnabled = (mediaType: TMediaType) => {
|
||||||
const { internetType } = store.getState().app;
|
const { netInfoState } = store.getState().app;
|
||||||
const mediaDownloadPreference = userPreferences.getString<MediaDownloadOption>(mediaType);
|
const mediaDownloadPreference = userPreferences.getString(mediaType) as MediaDownloadOption;
|
||||||
|
|
||||||
let defaultValueByMediaType = false;
|
let defaultValueByMediaType = false;
|
||||||
if (mediaDownloadPreference === null) {
|
if (mediaDownloadPreference === null) {
|
||||||
|
@ -23,12 +23,12 @@ export const fetchAutoDownloadEnabled = (mediaType: TMediaType) => {
|
||||||
}
|
}
|
||||||
if (mediaType === 'audioPreferenceDownload' || mediaType === 'videoPreferenceDownload') {
|
if (mediaType === 'audioPreferenceDownload' || mediaType === 'videoPreferenceDownload') {
|
||||||
// The same as 'wifi'
|
// The same as 'wifi'
|
||||||
defaultValueByMediaType = internetType === NetInfoStateType.wifi;
|
defaultValueByMediaType = netInfoState === NetInfoStateType.wifi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(mediaDownloadPreference === 'wifi' && internetType === NetInfoStateType.wifi) ||
|
(mediaDownloadPreference === 'wifi' && netInfoState === NetInfoStateType.wifi) ||
|
||||||
mediaDownloadPreference === 'wifi_mobile_data' ||
|
mediaDownloadPreference === 'wifi_mobile_data' ||
|
||||||
defaultValueByMediaType
|
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 sanitizeString = (value: string) => {
|
||||||
const urlWithoutQueryString = value.split('?')[0];
|
const urlWithoutQueryString = value.split('?')[0];
|
||||||
|
@ -113,7 +113,7 @@ export const searchMediaFileAsync = async ({
|
||||||
try {
|
try {
|
||||||
const serverUrl = store.getState().server.server;
|
const serverUrl = store.getState().server.server;
|
||||||
const serverUrlParsed = serverUrlParsedAsPath(serverUrl);
|
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 fileUrlSanitized = sanitizeString(urlToCache);
|
||||||
const filename = `${fileUrlSanitized}.${getExtension(type, mimeType)}`;
|
const filename = `${fileUrlSanitized}.${getExtension(type, mimeType)}`;
|
||||||
const filePath = `${folderPath}${filename}`;
|
const filePath = `${folderPath}${filename}`;
|
||||||
|
@ -129,7 +129,7 @@ export const searchMediaFileAsync = async ({
|
||||||
export const deleteMediaFiles = async (serverUrl: string): Promise<void> => {
|
export const deleteMediaFiles = async (serverUrl: string): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const serverUrlParsed = serverUrlParsedAsPath(serverUrl);
|
const serverUrlParsed = serverUrlParsedAsPath(serverUrl);
|
||||||
const path = `${LOCAL_DOCUMENT_PATH}${serverUrlParsed}`;
|
const path = `${LOCAL_DOCUMENT_DIRECTORY}${serverUrlParsed}`;
|
||||||
await FileSystem.deleteAsync(path, { idempotent: true });
|
await FileSystem.deleteAsync(path, { idempotent: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(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 => {
|
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;
|
return attachmentUrl;
|
||||||
}
|
}
|
||||||
if (attachmentUrl && attachmentUrl.startsWith('http')) {
|
if (attachmentUrl && attachmentUrl.startsWith('http')) {
|
||||||
|
|
|
@ -14,9 +14,9 @@ class UserPreferences {
|
||||||
this.mmkv = MMKV;
|
this.mmkv = MMKV;
|
||||||
}
|
}
|
||||||
|
|
||||||
getString<T = string>(key: string) {
|
getString(key: string) {
|
||||||
try {
|
try {
|
||||||
return (this.mmkv.getString(key) as T) ?? null;
|
return this.mmkv.getString(key) ?? null;
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import NetInfo, { NetInfoState, NetInfoStateType } from '@react-native-community/netinfo';
|
import NetInfo, { NetInfoState, NetInfoStateType } from '@react-native-community/netinfo';
|
||||||
|
|
||||||
import { setInternetType } from '../../actions/app';
|
import { setNetInfoState } from '../../actions/app';
|
||||||
|
|
||||||
export default () =>
|
export default () =>
|
||||||
(createStore: any) =>
|
(createStore: any) =>
|
||||||
|
@ -9,7 +9,7 @@ export default () =>
|
||||||
let currentType: NetInfoStateType | undefined;
|
let currentType: NetInfoStateType | undefined;
|
||||||
const handleInternetStateChange = (nextState: NetInfoState) => {
|
const handleInternetStateChange = (nextState: NetInfoState) => {
|
||||||
if (nextState.type !== currentType) {
|
if (nextState.type !== currentType) {
|
||||||
store.dispatch(setInternetType(nextState.type));
|
store.dispatch(setNetInfoState(nextState.type));
|
||||||
currentType = nextState.type;
|
currentType = nextState.type;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,7 +12,7 @@ export interface IApp {
|
||||||
foreground: boolean;
|
foreground: boolean;
|
||||||
background: boolean;
|
background: boolean;
|
||||||
notificationPresenceCap: boolean;
|
notificationPresenceCap: boolean;
|
||||||
internetType?: NetInfoStateType;
|
netInfoState?: NetInfoStateType | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialState: IApp = {
|
export const initialState: IApp = {
|
||||||
|
@ -23,7 +23,7 @@ export const initialState: IApp = {
|
||||||
foreground: true,
|
foreground: true,
|
||||||
background: false,
|
background: false,
|
||||||
notificationPresenceCap: false,
|
notificationPresenceCap: false,
|
||||||
internetType: undefined
|
netInfoState: null
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function app(state = initialState, action: TActionApp): IApp {
|
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:
|
case APP.SET_INTERNET_TYPE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
internetType: action.internetType
|
netInfoState: action.netInfoState
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Reference in New Issue