From 5a23129a50468171606409d1f601d34f49ac89f9 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 17 Apr 2018 10:40:09 -0400 Subject: [PATCH] Fixed null pointer in ProfilePicture (#1595) --- app/components/profile_picture/profile_picture.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/components/profile_picture/profile_picture.js b/app/components/profile_picture/profile_picture.js index 8816748fb..3c6f5adb5 100644 --- a/app/components/profile_picture/profile_picture.js +++ b/app/components/profile_picture/profile_picture.js @@ -52,7 +52,7 @@ export default class ProfilePicture extends PureComponent { if (edit && imageUri) { this.setImageURL(imageUri); - } else { + } else if (user) { ImageCacheManager.cache('', Client4.getProfilePictureUrl(user.id, user.last_picture_update), this.setImageURL); } } @@ -63,6 +63,18 @@ export default class ProfilePicture extends PureComponent { } } + componentWillUpdate(nextProps) { + if (Boolean(nextProps.user) !== Boolean(this.props.user) || nextProps.user.id !== this.props.user.id) { + this.setState({pictureUrl: null}); + + const nextUser = nextProps.user; + + if (nextUser) { + ImageCacheManager.cache('', Client4.getProfilePictureUrl(nextUser.id, nextUser.last_picture_update), this.setImageURL); + } + } + } + setImageURL = (pictureUrl) => { this.setState({pictureUrl}); };