Rocket.Chat.ReactNative/app/lib/methods/autoDownloadPreference.ts

28 lines
980 B
TypeScript
Raw Normal View History

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';
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) => {
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)
);
};