2023-05-11 23:20:48 +00:00
|
|
|
import NetInfo, { NetInfoStateType } from '@react-native-community/netinfo';
|
|
|
|
|
|
|
|
import {
|
|
|
|
IMAGES_PREFERENCE_DOWNLOAD,
|
|
|
|
AUDIO_PREFERENCE_DOWNLOAD,
|
|
|
|
VIDEO_PREFERENCE_DOWNLOAD,
|
|
|
|
MediaDownloadOption
|
2023-05-30 14:07:34 +00:00
|
|
|
} from '../constants';
|
|
|
|
import userPreferences from './userPreferences';
|
|
|
|
import { IUser, IUserMessage } from '../../definitions';
|
2023-05-11 23:20:48 +00:00
|
|
|
|
|
|
|
type TMediaType = typeof IMAGES_PREFERENCE_DOWNLOAD | typeof AUDIO_PREFERENCE_DOWNLOAD | typeof VIDEO_PREFERENCE_DOWNLOAD;
|
|
|
|
interface IUsersParam {
|
|
|
|
user: IUser;
|
|
|
|
author?: IUserMessage;
|
|
|
|
}
|
|
|
|
|
2023-05-30 14:07:34 +00:00
|
|
|
export const isAutoDownloadEnabled = async (mediaType: TMediaType, userParam?: IUsersParam) => {
|
2023-05-11 23:20:48 +00:00
|
|
|
const mediaDownloadPreference = userPreferences.getString(mediaType);
|
|
|
|
const netInfoState = await NetInfo.fetch();
|
|
|
|
|
|
|
|
return (
|
|
|
|
(mediaDownloadPreference === MediaDownloadOption.WIFI && netInfoState.type === NetInfoStateType.wifi) ||
|
|
|
|
mediaDownloadPreference === MediaDownloadOption.WIFI_MOBILE_DATA ||
|
2023-05-30 14:07:34 +00:00
|
|
|
(userParam && userParam.author?._id === userParam.user.id)
|
2023-05-11 23:20:48 +00:00
|
|
|
);
|
|
|
|
};
|