From 0f3d62364b7efaa553c711f2a63852a09b34277c Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Fri, 1 Apr 2016 11:53:49 -0400 Subject: Properly display webhook username/icon in search results --- webapp/components/post.jsx | 11 +--------- webapp/components/posts_view.jsx | 2 ++ webapp/components/rhs_root_post.jsx | 13 +----------- webapp/components/search_results_item.jsx | 35 ++++++++++++++++++++++++------- webapp/utils/utils.jsx | 15 +++++++++++++ 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/webapp/components/post.jsx b/webapp/components/post.jsx index bbf8d9bf6..7294cf163 100644 --- a/webapp/components/post.jsx +++ b/webapp/components/post.jsx @@ -185,18 +185,9 @@ export default class Post extends React.Component { let profilePic = null; if (!this.props.hideProfilePic) { - let src = '/api/v1/users/' + post.user_id + '/image?time=' + timestamp; - if (post.props && post.props.from_webhook && global.window.mm_config.EnablePostIconOverride === 'true') { - if (post.props.override_icon_url) { - src = post.props.override_icon_url; - } else { - src = Constants.DEFAULT_WEBHOOK_LOGO; - } - } - profilePic = ( diff --git a/webapp/components/posts_view.jsx b/webapp/components/posts_view.jsx index ffe04daa1..aa7f445ce 100644 --- a/webapp/components/posts_view.jsx +++ b/webapp/components/posts_view.jsx @@ -204,10 +204,12 @@ export default class PostsView extends React.Component { // the previous post was made by the same user as the current post, // the previous post is not a comment, // the current post is not a comment, + // the previous post is not from a webhook // the current post is not from a webhook if (prevPostUserId === postUserId && !prevPostIsComment && !postIsComment && + !prevPostFromWebhook && !postFromWebhook) { hideProfilePic = true; } diff --git a/webapp/components/rhs_root_post.jsx b/webapp/components/rhs_root_post.jsx index 7a7c5f692..9a207e429 100644 --- a/webapp/components/rhs_root_post.jsx +++ b/webapp/components/rhs_root_post.jsx @@ -213,21 +213,10 @@ export default class RhsRootPost extends React.Component { ); } - let src = '/api/v1/users/' + post.user_id + '/image?time=' + timestamp; - if (post.props && post.props.from_webhook && global.window.mm_config.EnablePostIconOverride === 'true') { - if (post.props.override_icon_url) { - src = post.props.override_icon_url; - } else { - src = Constants.DEFAULT_WEBHOOK_LOGO; - } - } else if (Utils.isSystemMessage(post)) { - src = Constants.SYSTEM_MESSAGE_PROFILE_IMAGE; - } - const profilePic = ( diff --git a/webapp/components/search_results_item.jsx b/webapp/components/search_results_item.jsx index 75cbcb2a0..58f09c0e0 100644 --- a/webapp/components/search_results_item.jsx +++ b/webapp/components/search_results_item.jsx @@ -1,11 +1,13 @@ // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import UserStore from 'stores/user_store.jsx'; import UserProfile from './user_profile.jsx'; + +import UserStore from 'stores/user_store.jsx'; + import * as GlobalActions from 'action_creators/global_actions.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx'; - +import * as Utils from 'utils/utils.jsx'; import Constants from 'utils/constants.jsx'; import {FormattedMessage, FormattedDate} from 'react-intl'; @@ -29,6 +31,7 @@ export default class SearchResultsItem extends React.Component { const channel = this.props.channel; const timestamp = UserStore.getCurrentUser().update_at; const user = this.props.user || {}; + const post = this.props.post; if (channel) { channelName = channel.display_name; @@ -47,13 +50,23 @@ export default class SearchResultsItem extends React.Component { mentionHighlight: this.props.isMentionSearch }; + 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; + } + return (

    -
  • +
  • + +
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx index 9b03ef32a..3b7583f15 100644 --- a/webapp/utils/utils.jsx +++ b/webapp/utils/utils.jsx @@ -1379,3 +1379,18 @@ export function localizeMessage(id, defaultMessage) { return id; } + +export function getProfilePicSrcForPost(post, timestamp) { + let src = '/api/v1/users/' + post.user_id + '/image?time=' + timestamp; + if (post.props && post.props.from_webhook && global.window.mm_config.EnablePostIconOverride === 'true') { + if (post.props.override_icon_url) { + src = post.props.override_icon_url; + } else { + src = Constants.DEFAULT_WEBHOOK_LOGO; + } + } else if (isSystemMessage(post)) { + src = Constants.SYSTEM_MESSAGE_PROFILE_IMAGE; + } + + return src; +} -- cgit v1.2.3-1-g7c22