// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import PostTime from './post_time.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import * as PostActions from 'actions/post_actions.jsx'; import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; import * as Utils from 'utils/utils.jsx'; import Constants from 'utils/constants.jsx'; import {Tooltip, OverlayTrigger} from 'react-bootstrap'; import React from 'react'; import {FormattedMessage} from 'react-intl'; export default class PostInfo extends React.Component { constructor(props) { super(props); this.handleDropdownClick = this.handleDropdownClick.bind(this); this.handlePermalink = this.handlePermalink.bind(this); this.removePost = this.removePost.bind(this); this.flagPost = this.flagPost.bind(this); this.unflagPost = this.unflagPost.bind(this); } handleDropdownClick(e) { var position = $('#post-list').height() - $(e.target).offset().top; var dropdown = $(e.target).closest('.col__reply').find('.dropdown-menu'); if (position < dropdown.height()) { dropdown.addClass('bottom'); } } componentDidMount() { $('#post_dropdown' + this.props.post.id).on('shown.bs.dropdown', () => this.props.handleDropdownOpened(true)); $('#post_dropdown' + this.props.post.id).on('hidden.bs.dropdown', () => this.props.handleDropdownOpened(false)); } createDropdown() { var post = this.props.post; var isOwner = this.props.currentUser.id === post.user_id; var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); const isSystemMessage = post.type && post.type.startsWith(Constants.SYSTEM_MESSAGE_PREFIX); if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING || Utils.isPostEphemeral(post)) { return ''; } var type = 'Post'; if (post.root_id && post.root_id.length > 0) { type = 'Comment'; } var dropdownContents = []; var dataComments = 0; if (type === 'Post') { dataComments = this.props.commentCount; } if (this.props.allowReply) { dropdownContents.push(
  • ); } if (Utils.isMobile()) { if (this.props.isFlagged) { dropdownContents.push(
  • ); } else { dropdownContents.push(
  • ); } } dropdownContents.push(
  • ); if (isOwner || isAdmin) { dropdownContents.push(
  • { e.preventDefault(); GlobalActions.showDeletePostModal(post, dataComments); }} >
  • ); } if (isOwner && !isSystemMessage) { dropdownContents.push(
  • ); } if (dropdownContents.length === 0) { return ''; } return (
    {'×'} ); } flagPost(e) { e.preventDefault(); PostActions.flagPost(this.props.post.id); } unflagPost(e) { e.preventDefault(); PostActions.unflagPost(this.props.post.id); } render() { var post = this.props.post; var comments = ''; var showCommentClass = ''; var commentCountText = this.props.commentCount; const flagIcon = Constants.FLAG_ICON_SVG; if (this.props.commentCount >= 1) { showCommentClass = ' icon--show'; } else { commentCountText = ''; } if (post.state !== Constants.POST_FAILED && post.state !== Constants.POST_LOADING && !Utils.isPostEphemeral(post) && this.props.allowReply) { comments = ( {commentCountText} ); } let options; if (Utils.isPostEphemeral(post)) { options = (
  • {this.createRemovePostButton()}
  • ); } else { options = (
  • {this.createDropdown()}
    {comments}
  • ); } let flag; let flagFunc; let flagVisible = ''; let flagTooltip = ( ); if (this.props.isFlagged) { flagVisible = 'visible'; flag = ( ); flagFunc = this.unflagPost; flagTooltip = ( ); } else { flag = ( ); flagFunc = this.flagPost; } let flagTrigger; if (!Utils.isPostEphemeral(post)) { flagTrigger = ( {flag} ); } return ( ); } } PostInfo.defaultProps = { post: null, commentCount: 0, isLastComment: false, allowReply: false, sameUser: false }; PostInfo.propTypes = { post: React.PropTypes.object.isRequired, commentCount: React.PropTypes.number.isRequired, isLastComment: React.PropTypes.bool.isRequired, allowReply: React.PropTypes.bool.isRequired, handleCommentClick: React.PropTypes.func.isRequired, handleDropdownOpened: React.PropTypes.func.isRequired, sameUser: React.PropTypes.bool.isRequired, currentUser: React.PropTypes.object.isRequired, compactDisplay: React.PropTypes.bool, useMilitaryTime: React.PropTypes.bool.isRequired, isFlagged: React.PropTypes.bool };