Skip to content

Commit

Permalink
[FIX] Append server URL on avatar if necessary (#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello authored Jul 5, 2019
1 parent 3361110 commit 719cf33
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/containers/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import PropTypes from 'prop-types';
import { View } from 'react-native';
import FastImage from 'react-native-fast-image';

const formatUrl = (url, baseUrl, uriSize, avatarAuthURLFragment) => (
`${ baseUrl }${ url }?format=png&width=${ uriSize }&height=${ uriSize }${ avatarAuthURLFragment }`
);

const Avatar = React.memo(({
text, size, baseUrl, borderRadius, style, avatar, type, children, userId, token
}) => {
Expand All @@ -26,7 +30,14 @@ const Avatar = React.memo(({
avatarAuthURLFragment = `&rc_token=${ token }&rc_uid=${ userId }`;
}

const uri = avatar || `${ baseUrl }/avatar/${ room }?format=png&width=${ uriSize }&height=${ uriSize }${ avatarAuthURLFragment }`;

let uri;
if (avatar) {
uri = avatar.includes('http') ? avatar : formatUrl(avatar, baseUrl, uriSize, avatarAuthURLFragment);
} else {
uri = formatUrl(`/avatar/${ room }`, baseUrl, uriSize, avatarAuthURLFragment);
}


const image = (
<FastImage
Expand Down

0 comments on commit 719cf33

Please sign in to comment.