creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
This commit is contained in:
parent
b73cf46829
commit
7fc975f63e
|
@ -71,6 +71,7 @@ const Attachments: React.FC<IMessageAttachments> = React.memo(
|
||||||
getCustomEmoji={getCustomEmoji}
|
getCustomEmoji={getCustomEmoji}
|
||||||
style={style}
|
style={style}
|
||||||
isReply={isReply}
|
isReply={isReply}
|
||||||
|
author={author}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,12 @@ import moment from 'moment';
|
||||||
import { dequal } from 'dequal';
|
import { dequal } from 'dequal';
|
||||||
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
|
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
|
||||||
import { Sound } from 'expo-av/build/Audio/Sound';
|
import { Sound } from 'expo-av/build/Audio/Sound';
|
||||||
import NetInfo, { NetInfoStateType } from '@react-native-community/netinfo';
|
|
||||||
|
|
||||||
import Touchable from './Touchable';
|
import Touchable from './Touchable';
|
||||||
import Markdown from '../markdown';
|
import Markdown from '../markdown';
|
||||||
import { CustomIcon } from '../CustomIcon';
|
import { CustomIcon } from '../CustomIcon';
|
||||||
import sharedStyles from '../../views/Styles';
|
import sharedStyles from '../../views/Styles';
|
||||||
import { MediaDownloadOption, VIDEO_PREFERENCE_DOWNLOAD, themes } from '../../lib/constants';
|
import { themes } from '../../lib/constants';
|
||||||
import { isAndroid, isIOS } from '../../lib/methods/helpers';
|
import { isAndroid, isIOS } from '../../lib/methods/helpers';
|
||||||
import MessageContext from './Context';
|
import MessageContext from './Context';
|
||||||
import ActivityIndicator from '../ActivityIndicator';
|
import ActivityIndicator from '../ActivityIndicator';
|
||||||
|
@ -23,7 +22,7 @@ import { TSupportedThemes } from '../../theme';
|
||||||
import { downloadAudioFile, searchAudioFileAsync } from '../../lib/methods/audioFile';
|
import { downloadAudioFile, searchAudioFileAsync } from '../../lib/methods/audioFile';
|
||||||
import EventEmitter from '../../lib/methods/helpers/events';
|
import EventEmitter from '../../lib/methods/helpers/events';
|
||||||
import { PAUSE_AUDIO } from './constants';
|
import { PAUSE_AUDIO } from './constants';
|
||||||
import userPreferences from '../../lib/methods/userPreferences';
|
import { isAutoDownloadEnabled } from './helpers/mediaDownload/autoDownloadPreference';
|
||||||
|
|
||||||
interface IButton {
|
interface IButton {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
@ -173,13 +172,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
||||||
return this.setState({ loading: false });
|
return this.setState({ loading: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
const audioDownloadPreference = userPreferences.getString(VIDEO_PREFERENCE_DOWNLOAD);
|
const autoDownload = await isAutoDownloadEnabled('audioPreferenceDownload', { author, user });
|
||||||
const netInfoState = await NetInfo.fetch();
|
|
||||||
const autoDownload =
|
|
||||||
(audioDownloadPreference === MediaDownloadOption.WIFI && netInfoState.type === NetInfoStateType.wifi) ||
|
|
||||||
audioDownloadPreference === MediaDownloadOption.WIFI_MOBILE_DATA ||
|
|
||||||
author?._id === user.id;
|
|
||||||
|
|
||||||
if (autoDownload) {
|
if (autoDownload) {
|
||||||
await this.startDownload();
|
await this.startDownload();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,10 @@ import styles from './styles';
|
||||||
import { themes } from '../../lib/constants';
|
import { themes } from '../../lib/constants';
|
||||||
import MessageContext from './Context';
|
import MessageContext from './Context';
|
||||||
import { TGetCustomEmoji } from '../../definitions/IEmoji';
|
import { TGetCustomEmoji } from '../../definitions/IEmoji';
|
||||||
import { IAttachment } from '../../definitions';
|
import { IAttachment, IUserMessage } from '../../definitions';
|
||||||
import { TSupportedThemes, useTheme } from '../../theme';
|
import { TSupportedThemes, useTheme } from '../../theme';
|
||||||
import { formatAttachmentUrl } from '../../lib/methods/helpers/formatAttachmentUrl';
|
import { formatAttachmentUrl } from '../../lib/methods/helpers/formatAttachmentUrl';
|
||||||
|
import { isAutoDownloadEnabled } from './helpers/mediaDownload/autoDownloadPreference';
|
||||||
|
|
||||||
interface IMessageButton {
|
interface IMessageButton {
|
||||||
children: React.ReactElement;
|
children: React.ReactElement;
|
||||||
|
@ -29,6 +30,7 @@ interface IMessageImage {
|
||||||
style?: StyleProp<TextStyle>[];
|
style?: StyleProp<TextStyle>[];
|
||||||
isReply?: boolean;
|
isReply?: boolean;
|
||||||
getCustomEmoji?: TGetCustomEmoji;
|
getCustomEmoji?: TGetCustomEmoji;
|
||||||
|
author?: IUserMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImageProgress = createImageProgress(FastImage);
|
const ImageProgress = createImageProgress(FastImage);
|
||||||
|
@ -57,7 +59,7 @@ export const MessageImage = React.memo(({ imgUri, theme }: { imgUri: string; the
|
||||||
));
|
));
|
||||||
|
|
||||||
const ImageContainer = React.memo(
|
const ImageContainer = React.memo(
|
||||||
({ file, imageUrl, showAttachment, getCustomEmoji, style, isReply }: IMessageImage) => {
|
({ file, imageUrl, showAttachment, getCustomEmoji, style, isReply, author }: IMessageImage) => {
|
||||||
const { theme } = useTheme();
|
const { theme } = useTheme();
|
||||||
const { baseUrl, user } = useContext(MessageContext);
|
const { baseUrl, user } = useContext(MessageContext);
|
||||||
const img = imageUrl || formatAttachmentUrl(file.image_url, user.id, user.token, baseUrl);
|
const img = imageUrl || formatAttachmentUrl(file.image_url, user.id, user.token, baseUrl);
|
||||||
|
@ -66,6 +68,14 @@ const ImageContainer = React.memo(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAutoDownloadEnabled('imagesPreferenceDownload', { user, author }).then(result => {
|
||||||
|
if (result && file.title_link) {
|
||||||
|
// Since https://github.com/RocketChat/Rocket.Chat.ReactNative/pull/3370 the title_link is considered the full image
|
||||||
|
const imgBestQualityPreload = formatAttachmentUrl(file.title_link, user.id, user.token, baseUrl);
|
||||||
|
FastImage.preload([{ uri: imgBestQualityPreload }]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const onPress = () => {
|
const onPress = () => {
|
||||||
if (!showAttachment) {
|
if (!showAttachment) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
import NetInfo, { NetInfoStateType } from '@react-native-community/netinfo';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IMAGES_PREFERENCE_DOWNLOAD,
|
||||||
|
AUDIO_PREFERENCE_DOWNLOAD,
|
||||||
|
VIDEO_PREFERENCE_DOWNLOAD,
|
||||||
|
MediaDownloadOption
|
||||||
|
} from '../../../../lib/constants';
|
||||||
|
import userPreferences from '../../../../lib/methods/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;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isAutoDownloadEnabled = async (mediaType: TMediaType, { author, user }: IUsersParam) => {
|
||||||
|
const mediaDownloadPreference = userPreferences.getString(mediaType);
|
||||||
|
const netInfoState = await NetInfo.fetch();
|
||||||
|
|
||||||
|
return (
|
||||||
|
(mediaDownloadPreference === MediaDownloadOption.WIFI && netInfoState.type === NetInfoStateType.wifi) ||
|
||||||
|
mediaDownloadPreference === MediaDownloadOption.WIFI_MOBILE_DATA ||
|
||||||
|
author?._id === user.id
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useAutoDownloadEnabled = (mediaType: TMediaType, { author, user }: IUsersParam) => {
|
||||||
|
const [enabled, setEnabled] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleAutoDownload = async () => {
|
||||||
|
const result = await isAutoDownloadEnabled(mediaType, { author, user });
|
||||||
|
console.log('🚀 ~ file: autoDownloadPreference.ts:38 ~ handleAutoDownload ~ result:', result);
|
||||||
|
setEnabled(result);
|
||||||
|
};
|
||||||
|
handleAutoDownload();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return enabled;
|
||||||
|
};
|
Loading…
Reference in New Issue