From 719cf33c55120332e558a1141fa107700582fd9a Mon Sep 17 00:00:00 2001
From: Diego Mello <diegolmello@gmail.com>
Date: Fri, 5 Jul 2019 11:46:37 -0300
Subject: [PATCH] [FIX] Append server URL on avatar if necessary (#1038)

---
 app/containers/Avatar.js | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/app/containers/Avatar.js b/app/containers/Avatar.js
index 41eea348c..c616788cf 100644
--- a/app/containers/Avatar.js
+++ b/app/containers/Avatar.js
@@ -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
 }) => {
@@ -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
-- 
GitLab