// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import UserProfile from './user_profile.jsx'; import FileAttachmentList from './file_attachment_list.jsx'; import PostStore from 'stores/post_store.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; import * as GlobalActions from 'action_creators/global_actions.jsx'; import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx'; import * as Utils from 'utils/utils.jsx'; import Client from 'utils/web_client.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; import {FormattedMessage, FormattedDate} from 'react-intl'; import loadingGif from 'images/load.gif'; import React from 'react'; export default class RhsComment extends React.Component { constructor(props) { super(props); this.retryComment = this.retryComment.bind(this); this.handlePermalink = this.handlePermalink.bind(this); this.state = {}; } retryComment(e) { e.preventDefault(); var post = this.props.post; Client.createPost(post, (data) => { AsyncClient.getPosts(post.channel_id); var channel = ChannelStore.get(post.channel_id); var member = ChannelStore.getMember(post.channel_id); member.msg_count = channel.total_msg_count; member.last_viewed_at = (new Date()).getTime(); ChannelStore.setChannelMember(member); AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_POST, post: data }); }, () => { post.state = Constants.POST_FAILED; PostStore.updatePendingPost(post); this.forceUpdate(); } ); post.state = Constants.POST_LOADING; PostStore.updatePendingPost(post); this.forceUpdate(); } handlePermalink(e) { e.preventDefault(); GlobalActions.showGetPostLinkModal(this.props.post); } shouldComponentUpdate(nextProps) { if (!Utils.areObjectsEqual(nextProps.post, this.props.post)) { return true; } return false; } createDropdown() { var post = this.props.post; if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING || post.state === Constants.POST_DELETED) { return ''; } const isOwner = this.props.currentUser.id === post.user_id; var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); var dropdownContents = []; if (!Utils.isMobile()) { dropdownContents.push(
  • ); } if (isOwner) { dropdownContents.push(
  • ); } if (isOwner || isAdmin) { dropdownContents.push(
  • GlobalActions.showDeletePostModal(post, 0)} >
  • ); } if (dropdownContents.length === 0) { return ''; } return (
    ); } else if (post.state === Constants.POST_LOADING) { postClass += ' post-waiting'; loading = ( ); } else if (this.props.post.state === Constants.POST_DELETED) { message = ( ); } var dropdown = this.createDropdown(); var fileAttachment; if (post.filenames && post.filenames.length > 0) { fileAttachment = ( ); } return (
    • {dropdown}
    {loading} {message}
    {fileAttachment}
    ); } } RhsComment.propTypes = { post: React.PropTypes.object, user: React.PropTypes.object.isRequired, currentUser: React.PropTypes.object.isRequired };