mattermost-mobile/app/components/post_profile_picture/post_profile_picture.js
Mattermost Build 5492cd5e46 Automated cherry pick of #2961 (#2985)
* Enable emojis for profile icons from webhooks

Removes borders from profile icons when it is from a custom URL.

* feat: reapply border for all profile pictures and shrink emojis

* feat: remove border from emoji profile pictures

* feat: decide if post has emoji icon through props instead of url

* refactor: better checking of potentially undefined property

Co-Authored-By: Elias Nahum <nahumhbl@gmail.com>
2019-07-18 10:26:39 -04:00

105 lines
3.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {Image, TouchableOpacity, View} from 'react-native';
import AppIcon from 'app/components/app_icon';
import ProfilePicture from 'app/components/profile_picture';
import {emptyFunction} from 'app/utils/general';
import webhookIcon from 'assets/images/icons/webhook.jpg';
import {ViewTypes} from 'app/constants';
export default class PostProfilePicture extends PureComponent {
static propTypes = {
enablePostIconOverride: PropTypes.bool,
fromWebHook: PropTypes.bool,
isSystemMessage: PropTypes.bool,
fromAutoResponder: PropTypes.bool,
overrideIconUrl: PropTypes.string,
onViewUserProfile: PropTypes.func,
theme: PropTypes.object,
userId: PropTypes.string,
isBot: PropTypes.bool,
isEmoji: PropTypes.bool,
};
static defaultProps = {
onViewUserProfile: emptyFunction,
};
render() {
const {
enablePostIconOverride,
fromWebHook,
isSystemMessage,
fromAutoResponder,
onViewUserProfile,
overrideIconUrl,
theme,
userId,
isBot,
isEmoji,
} = this.props;
if (isSystemMessage && !fromAutoResponder && !isBot) {
return (
<View>
<AppIcon
color={theme.centerChannelColor}
height={ViewTypes.PROFILE_PICTURE_SIZE}
width={ViewTypes.PROFILE_PICTURE_SIZE}
/>
</View>
);
}
if (fromWebHook && enablePostIconOverride) {
const icon = overrideIconUrl ? {uri: overrideIconUrl} : webhookIcon;
const frameSize = ViewTypes.PROFILE_PICTURE_SIZE;
const pictureSize = isEmoji ? ViewTypes.PROFILE_PICTURE_EMOJI_SIZE : ViewTypes.PROFILE_PICTURE_SIZE;
const borderRadius = isEmoji ? 0 : ViewTypes.PROFILE_PICTURE_SIZE / 2;
return (
<View
style={{
borderRadius,
overflow: 'hidden',
justifyContent: 'center',
alignItems: 'center',
height: frameSize,
width: frameSize,
}}
>
<Image
source={icon}
style={{
height: pictureSize,
width: pictureSize,
}}
/>
</View>
);
}
const showProfileStatus = !fromAutoResponder;
let component = (
<ProfilePicture
userId={userId}
size={ViewTypes.PROFILE_PICTURE_SIZE}
showStatus={showProfileStatus}
/>
);
if (!fromWebHook) {
component = (
<TouchableOpacity onPress={onViewUserProfile}>
{component}
</TouchableOpacity>
);
}
return component;
}
}