2020-04-30 20:05:59 +00:00
|
|
|
import React, { useContext } from 'react';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { StyleSheet } from 'react-native';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2018-09-19 14:18:32 +00:00
|
|
|
|
2020-04-30 20:05:59 +00:00
|
|
|
import Touchable from './Touchable';
|
2019-08-27 12:25:38 +00:00
|
|
|
import Markdown from '../markdown';
|
2017-12-28 17:40:10 +00:00
|
|
|
import openLink from '../../utils/openLink';
|
2020-06-15 14:00:46 +00:00
|
|
|
import { isIOS } from '../../utils/deviceInfo';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { formatAttachmentUrl } from '../../lib/utils';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2020-04-30 20:05:59 +00:00
|
|
|
import MessageContext from './Context';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-08-30 12:45:56 +00:00
|
|
|
const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(isIOS ? [] : ['video/3gp', 'video/mkv'])];
|
2021-07-22 20:09:06 +00:00
|
|
|
const isTypeSupported = (type: any) => SUPPORTED_TYPES.indexOf(type) !== -1;
|
2017-12-02 13:19:58 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2018-09-11 16:32:52 +00:00
|
|
|
button: {
|
2017-12-02 13:19:58 +00:00
|
|
|
flex: 1,
|
2018-09-11 16:32:52 +00:00
|
|
|
borderRadius: 4,
|
|
|
|
height: 150,
|
2019-03-29 19:36:07 +00:00
|
|
|
marginBottom: 6,
|
2018-09-11 16:32:52 +00:00
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center'
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-22 20:09:06 +00:00
|
|
|
interface IMessageVideo {
|
|
|
|
file: {
|
|
|
|
video_type: string;
|
|
|
|
video_url: string;
|
|
|
|
description: string;
|
|
|
|
};
|
|
|
|
showAttachment: Function;
|
|
|
|
getCustomEmoji: Function;
|
|
|
|
theme: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Video = React.memo(({ file, showAttachment, getCustomEmoji, theme }: IMessageVideo) => {
|
2020-04-30 20:05:59 +00:00
|
|
|
const { baseUrl, user } = useContext(MessageContext);
|
2019-05-20 20:43:50 +00:00
|
|
|
if (!baseUrl) {
|
|
|
|
return null;
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
const onPress = () => {
|
2018-09-25 19:28:42 +00:00
|
|
|
if (isTypeSupported(file.video_type)) {
|
2019-12-18 21:13:11 +00:00
|
|
|
return showAttachment(file);
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
const uri = formatAttachmentUrl(file.video_url, user.id, user.token, baseUrl);
|
2019-12-04 16:39:53 +00:00
|
|
|
openLink(uri, theme);
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-05-20 20:43:50 +00:00
|
|
|
<Touchable
|
|
|
|
onPress={onPress}
|
2020-06-15 14:00:46 +00:00
|
|
|
style={[styles.button, { backgroundColor: themes[theme].videoBackground }]}
|
2019-12-04 16:39:53 +00:00
|
|
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
2019-05-20 20:43:50 +00:00
|
|
|
>
|
|
|
|
<CustomIcon
|
2020-07-27 19:53:33 +00:00
|
|
|
name='play-filled'
|
2019-05-20 20:43:50 +00:00
|
|
|
size={54}
|
2019-12-04 16:39:53 +00:00
|
|
|
color={themes[theme].buttonText}
|
2019-05-20 20:43:50 +00:00
|
|
|
/>
|
|
|
|
</Touchable>
|
2021-07-22 20:09:06 +00:00
|
|
|
{/*@ts-ignore*/}
|
2020-02-27 18:34:20 +00:00
|
|
|
<Markdown msg={file.description} baseUrl={baseUrl} username={user.username} getCustomEmoji={getCustomEmoji} theme={theme} />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-05-20 20:43:50 +00:00
|
|
|
);
|
2021-02-26 16:01:45 +00:00
|
|
|
}, (prevProps, nextProps) => dequal(prevProps.file, nextProps.file) && prevProps.theme === nextProps.theme);
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
export default Video;
|