// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import PostMessageContainer from 'components/post_view/components/post_message_container.jsx'; import UserProfile from './user_profile.jsx'; import FileAttachmentListContainer from './file_attachment_list_container.jsx'; import ProfilePicture from './profile_picture.jsx'; import CommentIcon from 'components/common/comment_icon.jsx'; import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {flagPost, unflagPost} from 'actions/post_actions.jsx'; import PostFlagIcon from 'components/common/post_flag_icon.jsx'; import * as Utils from 'utils/utils.jsx'; import * as PostUtils from 'utils/post_utils.jsx'; import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; import PropTypes from 'prop-types'; import React from 'react'; import {FormattedMessage, FormattedDate} from 'react-intl'; import {browserHistory, Link} from 'react-router/es6'; export default class SearchResultsItem extends React.Component { constructor(props) { super(props); this.handleFocusRHSClick = this.handleFocusRHSClick.bind(this); this.shrinkSidebar = this.shrinkSidebar.bind(this); this.unflagPost = this.unflagPost.bind(this); this.flagPost = this.flagPost.bind(this); this.state = { currentTeamDisplayName: TeamStore.getCurrent().name, width: '', height: '' }; } componentDidMount() { window.addEventListener('resize', () => { Utils.updateWindowDimensions(this); }); } componentWillUnmount() { window.removeEventListener('resize', () => { Utils.updateWindowDimensions(this); }); } hideSidebar() { $('.sidebar--right').removeClass('move--left'); } shrinkSidebar() { setTimeout(() => { this.props.shrink(); }); } handleFocusRHSClick(e) { e.preventDefault(); GlobalActions.emitPostFocusRightHandSideFromSearch(this.props.post, this.props.isMentionSearch); } flagPost(e) { e.preventDefault(); flagPost(this.props.post.id); } unflagPost(e) { e.preventDefault(); unflagPost(this.props.post.id); } timeTag(post) { return ( ); } renderTimeTag(post) { return Utils.isMobile() ? this.timeTag(post) : ( {this.timeTag(post)} ); } render() { let channelName = null; const channel = this.props.channel; const timestamp = UserStore.getCurrentUser().last_picture_update; const user = this.props.user || {}; const post = this.props.post; let idCount = -1; if (this.props.lastPostCount >= 0 && this.props.lastPostCount < Constants.TEST_ID_COUNT) { idCount = this.props.lastPostCount; } if (channel) { channelName = channel.display_name; if (channel.type === 'D') { channelName = ( ); } } let overrideUsername; let disableProfilePopover = false; if (post.props && post.props.from_webhook && post.props.override_username && global.window.mm_config.EnablePostUsernameOverride === 'true') { overrideUsername = post.props.override_username; disableProfilePopover = true; } let botIndicator; if (post.props && post.props.from_webhook) { botIndicator =
{Constants.BOT_NAME}
; } const profilePic = ( ); let compactClass = ''; const profilePicContainer = (
{profilePic}
); if (this.props.compactDisplay) { compactClass = ' post--compact'; } let postClass = ''; if (PostUtils.isEdited(this.props.post)) { postClass += ' post--edited'; } let fileAttachment = null; if (post.file_ids && post.file_ids.length > 0) { fileAttachment = ( ); } let message; let flagContent; let rhsControls; if (post.state === Constants.POST_DELETED) { message = (

); } else { flagContent = ( ); rhsControls = (
{ if (Utils.isMobile()) { AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_SEARCH, results: null }); AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_SEARCH_TERM, term: null, do_search: false, is_mention_search: false }); AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_POST_SELECTED, postId: null }); this.hideSidebar(); } this.shrinkSidebar(); browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/pl/' + post.id); } } className='search-item__jump' >
); message = ( ); } let pinnedBadge; if (post.is_pinned) { pinnedBadge = ( ); } return (

{channelName}
{profilePicContainer}
{botIndicator}
{this.renderTimeTag(post)} {pinnedBadge} {flagContent}
{rhsControls}
{message} {fileAttachment}
); } } SearchResultsItem.propTypes = { post: PropTypes.object, lastPostCount: PropTypes.number, user: PropTypes.object, channel: PropTypes.object, compactDisplay: PropTypes.bool, isMentionSearch: PropTypes.bool, isFlaggedSearch: PropTypes.bool, term: PropTypes.string, useMilitaryTime: PropTypes.bool.isRequired, shrink: PropTypes.func, isFlagged: PropTypes.bool, isBusy: PropTypes.bool, status: PropTypes.string };