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/utils/channel_intro_messages.jsx | 6 ++---- webapp/utils/post_utils.jsx | 11 ++++++++--- webapp/utils/utils.jsx | 11 +++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) (limited to 'webapp/utils') diff --git a/webapp/utils/channel_intro_messages.jsx b/webapp/utils/channel_intro_messages.jsx index c874bfc73..6390f615c 100644 --- a/webapp/utils/channel_intro_messages.jsx +++ b/webapp/utils/channel_intro_messages.jsx @@ -13,8 +13,6 @@ import Constants from 'utils/constants.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import ProfilePicture from 'components/profile_picture.jsx'; -import {Client4} from 'mattermost-redux/client'; - import {showManagementOptions} from './channel_utils.jsx'; import React from 'react'; @@ -52,7 +50,7 @@ export function createGMIntroMessage(channel, centeredIntro) { pictures.push(
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