import React from 'react'; import PropTypes from 'prop-types'; import { View, StyleSheet, TouchableHighlight, Text, TouchableOpacity } from 'react-native'; import { connect } from 'react-redux'; import Icon from 'react-native-vector-icons/MaterialIcons'; import moment from 'moment'; import { actionsShow, errorActionsShow } from '../../actions/messages'; import Image from './Image'; import User from './User'; import Avatar from '../Avatar'; import Audio from './Audio'; import Video from './Video'; import Markdown from './Markdown'; import Url from './Url'; import Reply from './Reply'; import messageStatus from '../../constants/messagesStatus'; const styles = StyleSheet.create({ content: { flexGrow: 1, flexShrink: 1 }, message: { padding: 12, paddingTop: 6, paddingBottom: 6, flexDirection: 'row', transform: [{ scaleY: -1 }] }, textInfo: { fontStyle: 'italic', color: '#a0a0a0' }, editing: { backgroundColor: '#fff5df' } }); @connect(state => ({ message: state.messages.message, editing: state.messages.editing }), dispatch => ({ actionsShow: actionMessage => dispatch(actionsShow(actionMessage)), errorActionsShow: actionMessage => dispatch(errorActionsShow(actionMessage)) })) export default class Message extends React.Component { static propTypes = { item: PropTypes.object.isRequired, baseUrl: PropTypes.string.isRequired, Message_TimeFormat: PropTypes.string.isRequired, message: PropTypes.object.isRequired, user: PropTypes.object.isRequired, editing: PropTypes.bool, actionsShow: PropTypes.func, errorActionsShow: PropTypes.func } onLongPress() { const { item } = this.props; this.props.actionsShow(JSON.parse(JSON.stringify(item))); } onErrorPress() { const { item } = this.props; this.props.errorActionsShow(JSON.parse(JSON.stringify(item))); } isDeleted() { return this.props.item.t === 'rm'; } isPinned() { return this.props.item.t === 'message_pinned'; } hasError() { return this.props.item.status === messageStatus.ERROR; } attachments() { if (this.props.item.attachments.length === 0) { return null; } const file = this.props.item.attachments[0]; const { baseUrl, user } = this.props; if (file.image_type) { return ; } else if (file.audio_type) { return