import React from 'react'; import PropTypes from 'prop-types'; import { View, StyleSheet, TouchableOpacity, Text } from 'react-native'; import { emojify } from 'react-emojione'; import Markdown from 'react-native-easy-markdown'; // eslint-disable-line import { connect } from 'react-redux'; import { actionsShow } from '../../actions/messages'; import Card from './Card'; import User from './User'; import Avatar from '../Avatar'; 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)) })) 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, editing: PropTypes.bool, actionsShow: PropTypes.func } onLongPress() { const { item } = this.props; this.props.actionsShow(JSON.parse(JSON.stringify(item))); } isDeleted() { return !this.props.item.msg; } attachments() { return this.props.item.attachments.length ? ( ) : null; } renderMessageContent() { if (this.isDeleted()) { return Message removed; } const msg = emojify(this.props.item.msg, { output: 'unicode' }); return ( {msg} ); } render() { const { item, message, editing } = this.props; const extraStyle = {}; if (item.temp) { extraStyle.opacity = 0.3; } const username = item.alias || item.u.username; const isEditing = message._id === item._id && editing; return ( this.onLongPress()} disabled={this.isDeleted()} style={[styles.message, extraStyle, isEditing ? styles.editing : null]} > {this.attachments()} {this.renderMessageContent(item)} ); } }