Skip to content
Snippets Groups Projects
Unverified Commit 719cf33c authored by Diego Mello's avatar Diego Mello Committed by GitHub
Browse files

[FIX] Append server URL on avatar if necessary (#1038)

parent 33611103
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,10 @@ import PropTypes from 'prop-types'; ...@@ -3,6 +3,10 @@ import PropTypes from 'prop-types';
import { View } from 'react-native'; import { View } from 'react-native';
import FastImage from 'react-native-fast-image'; 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(({ const Avatar = React.memo(({
text, size, baseUrl, borderRadius, style, avatar, type, children, userId, token text, size, baseUrl, borderRadius, style, avatar, type, children, userId, token
}) => { }) => {
...@@ -26,7 +30,14 @@ const Avatar = React.memo(({ ...@@ -26,7 +30,14 @@ const Avatar = React.memo(({
avatarAuthURLFragment = `&rc_token=${ token }&rc_uid=${ userId }`; 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 = ( const image = (
<FastImage <FastImage
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment