From 673f3a1144884373540030a8f5cca3bad3d00b63 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 19 Jul 2017 13:54:16 -0700 Subject: PLT-6689: fix user image requests (#6946) * fix user image requests * fix eslint errors and a few more cache busters --- webapp/components/post_view/post/post.jsx | 11 ++--------- webapp/components/rhs_comment.jsx | 6 ++---- webapp/components/rhs_root_post.jsx | 5 ++--- webapp/components/search_results_item.jsx | 4 +--- webapp/components/suggestion/at_mention_provider.jsx | 3 +-- webapp/components/suggestion/search_user_provider.jsx | 3 +-- webapp/components/suggestion/switch_channel_provider.jsx | 5 +++-- webapp/components/user_profile.jsx | 3 +-- .../user_settings_general/user_settings_general.jsx | 3 +-- webapp/components/webrtc/components/webrtc_notification.jsx | 3 +-- webapp/components/webrtc/webrtc_controller.jsx | 7 +++---- webapp/utils/channel_intro_messages.jsx | 6 ++---- webapp/utils/post_utils.jsx | 11 ++++++++--- webapp/utils/utils.jsx | 11 +++++++++++ 14 files changed, 39 insertions(+), 42 deletions(-) diff --git a/webapp/components/post_view/post/post.jsx b/webapp/components/post_view/post/post.jsx index eda4405bb..4491d888c 100644 --- a/webapp/components/post_view/post/post.jsx +++ b/webapp/components/post_view/post/post.jsx @@ -199,13 +199,6 @@ export default class Post extends React.PureComponent { const isSystemMessage = PostUtils.isSystemMessage(post); const fromWebhook = post.props && post.props.from_webhook === 'true'; - let timestamp = 0; - if (!this.props.user || this.props.user.last_picture_update == null) { - timestamp = this.props.currentUser.last_picture_update; - } else { - timestamp = this.props.user.last_picture_update; - } - let status = this.props.status; if (fromWebhook) { status = null; @@ -213,7 +206,7 @@ export default class Post extends React.PureComponent { let profilePic = ( ); } else if (PostUtils.isSystemMessage(post)) { diff --git a/webapp/components/rhs_comment.jsx b/webapp/components/rhs_comment.jsx index 568d85304..6592c487d 100644 --- a/webapp/components/rhs_comment.jsx +++ b/webapp/components/rhs_comment.jsx @@ -212,8 +212,6 @@ export default class RhsComment extends React.Component { const isEphemeral = Utils.isPostEphemeral(post); const isSystemMessage = PostUtils.isSystemMessage(post); - var timestamp = this.props.currentUser.last_picture_update; - let status = this.props.status; if (post.props && post.props.from_webhook === 'true') { status = null; @@ -277,7 +275,7 @@ export default class RhsComment extends React.Component { let profilePic = ( diff --git a/webapp/components/rhs_root_post.jsx b/webapp/components/rhs_root_post.jsx index fa72da167..1a28dc008 100644 --- a/webapp/components/rhs_root_post.jsx +++ b/webapp/components/rhs_root_post.jsx @@ -196,7 +196,6 @@ export default class RhsRootPost extends React.Component { const post = this.props.post; const user = this.props.user; const mattermostLogo = Constants.MATTERMOST_ICON_SVG; - var timestamp = user ? user.last_picture_update : 0; var channel = ChannelStore.get(post.channel_id); const isEphemeral = Utils.isPostEphemeral(post); @@ -303,7 +302,7 @@ export default class RhsRootPost extends React.Component { let profilePic = ( diff --git a/webapp/components/search_results_item.jsx b/webapp/components/search_results_item.jsx index 3b632ee5e..56b91fe68 100644 --- a/webapp/components/search_results_item.jsx +++ b/webapp/components/search_results_item.jsx @@ -9,7 +9,6 @@ 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'; @@ -113,7 +112,6 @@ export default class SearchResultsItem extends React.Component { 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; @@ -154,7 +152,7 @@ export default class SearchResultsItem extends React.Component { const profilePic = ( diff --git a/webapp/components/suggestion/switch_channel_provider.jsx b/webapp/components/suggestion/switch_channel_provider.jsx index ba060d924..ac4af9c8b 100644 --- a/webapp/components/suggestion/switch_channel_provider.jsx +++ b/webapp/components/suggestion/switch_channel_provider.jsx @@ -58,7 +58,7 @@ class SwitchChannelSuggestion extends Suggestion {
0; } -export function getProfilePicSrcForPost(post, timestamp) { - let src = Client4.getUsersRoute() + '/' + post.user_id + '/image?time=' + timestamp; +export function getProfilePicSrcForPost(post, user) { + let src = ''; + if (user && user.id === post.user_id) { + src = Utils.imageURLForUser(user); + } else { + src = Utils.imageURLForUser(post.user_id); + } + 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; diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx index b14bdaf11..0bd8c7bff 100644 --- a/webapp/utils/utils.jsx +++ b/webapp/utils/utils.jsx @@ -1023,6 +1023,17 @@ export function displayUsernameForUser(user) { return ''; } +export function imageURLForUser(userIdOrObject) { + if (typeof userIdOrObject == 'string') { + const profile = UserStore.getProfile(userIdOrObject); + if (profile) { + return imageURLForUser(profile); + } + return Client4.getUsersRoute() + '/' + userIdOrObject + '/image?_=' + Date.now(); + } + return Client4.getUsersRoute() + '/' + userIdOrObject.id + '/image?_=' + (userIdOrObject.last_picture_update || 0); +} + // Converts a file size in bytes into a human-readable string of the form '123MB'. export function fileSizeToString(bytes) { // it's unlikely that we'll have files bigger than this -- cgit v1.2.3-1-g7c22