// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; import FormattedText from 'app/components/formatted_text'; import FormattedTime from 'app/components/formatted_time'; import MattermostIcon from 'app/components/mattermost_icon'; import ProfilePicture from 'app/components/profile_picture'; import {makeStyleSheetFromTheme} from 'app/utils/theme'; import {isSystemMessage} from 'service/utils/post_utils.js'; const getStyleSheet = makeStyleSheetFromTheme((theme) => { return StyleSheet.create({ container: { backgroundColor: theme.centerChannelBg, flexDirection: 'row' }, rightColumn: { flex: 1, flexDirection: 'column', marginRight: 12 }, postInfoContainer: { alignItems: 'center', flexDirection: 'row', marginTop: 10 }, messageContainerWithReplyBar: { flexDirection: 'row' }, profilePictureContainer: { marginBottom: 10, marginRight: 10, marginLeft: 12, marginTop: 10 }, replyBar: { backgroundColor: theme.centerChannelColor, opacity: 0.1, marginRight: 10, width: 3 }, replyBarFirst: { marginTop: 10 }, replyBarLast: { marginBottom: 10 }, displayName: { fontSize: 14, fontWeight: '600', marginRight: 10, color: theme.centerChannelColor }, time: { color: theme.centerChannelColor, fontSize: 12, opacity: 0.5 }, commentedOn: { color: theme.centerChannelColor, lineHeight: 21 }, message: { color: theme.centerChannelColor, fontSize: 14, lineHeight: 21, marginBottom: 10 }, systemMessage: { opacity: 0.5 } }); }); export default class Post extends React.Component { static propTypes = { style: React.PropTypes.oneOfType([React.PropTypes.object, React.PropTypes.number]), post: React.PropTypes.object.isRequired, user: React.PropTypes.object, displayName: React.PropTypes.string, isFirstReply: React.PropTypes.bool, isLastReply: React.PropTypes.bool, commentedOnPost: React.PropTypes.object, commentedOnDisplayName: React.PropTypes.string, theme: React.PropTypes.object.isRequired }; renderCommentedOnMessage = (style) => { if (!this.props.commentedOnPost) { return null; } const displayName = this.props.commentedOnDisplayName; let name; if (displayName) { name = displayName; } else { name = ( ); } let apostrophe; if (displayName && displayName.slice(-1) === 's') { apostrophe = '\''; } else { apostrophe = '\'s'; } return ( ); } renderReplyBar = (style) => { if (!this.props.post.root_id) { return null; } const replyBarStyle = [style.replyBar]; if (this.props.isFirstReply && !this.props.commentedOnPost) { replyBarStyle.push(style.replyBarFirst); } if (this.props.isLastReply) { replyBarStyle.push(style.replyBarLast); } return ; } render() { const style = getStyleSheet(this.props.theme); let profilePicture; let displayName; let messageStyle; if (isSystemMessage(this.props.post)) { profilePicture = ( ); displayName = ( ); messageStyle = [style.message, style.systemMessage]; } else { profilePicture = ( ); if (this.props.displayName) { displayName = this.props.displayName; } else { displayName = ( ); } messageStyle = style.message; } if (this.props.commentedOnPost) { return ( {profilePicture} {displayName} {this.renderCommentedOnMessage(style)} {this.renderReplyBar(style)} {this.props.post.message} ); } return ( {profilePicture} {this.renderReplyBar(style)} {displayName} {this.props.post.message} ); } }