From c4d2b3c5e869f288091b0b885f05c67407fcd9fe Mon Sep 17 00:00:00 2001 From: OtavioStasiak Date: Thu, 24 Oct 2024 14:38:12 -0300 Subject: [PATCH 1/2] fix: added optional chaining to image URL logic --- app/containers/message/Urls.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/containers/message/Urls.tsx b/app/containers/message/Urls.tsx index 7e1ecaf5cd..80b7243930 100644 --- a/app/containers/message/Urls.tsx +++ b/app/containers/message/Urls.tsx @@ -127,7 +127,7 @@ const Url = ({ url }: { url: IUrl }) => { const { colors, theme } = useTheme(); const { baseUrl, user } = useContext(MessageContext); let image = url.image || url.url; - image = image.includes('http') ? image : `${baseUrl}/${image}?rc_uid=${user.id}&rc_token=${user.token}`; + image = image?.includes('http') ? image : `${baseUrl}/${image}?rc_uid=${user.id}&rc_token=${user.token}`; const onPress = () => openLink(url.url, theme); From 2646ff57aec0796ee6af4e9a102ccb6efc7d2ae5 Mon Sep 17 00:00:00 2001 From: OtavioStasiak Date: Fri, 25 Oct 2024 12:45:15 -0300 Subject: [PATCH 2/2] fix: Added getImageUrl function to prevent broken images --- app/containers/message/Urls.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/containers/message/Urls.tsx b/app/containers/message/Urls.tsx index 80b7243930..025b885fdc 100644 --- a/app/containers/message/Urls.tsx +++ b/app/containers/message/Urls.tsx @@ -126,8 +126,14 @@ type TImageLoadedState = 'loading' | 'done' | 'error'; const Url = ({ url }: { url: IUrl }) => { const { colors, theme } = useTheme(); const { baseUrl, user } = useContext(MessageContext); - let image = url.image || url.url; - image = image?.includes('http') ? image : `${baseUrl}/${image}?rc_uid=${user.id}&rc_token=${user.token}`; + const getImageUrl = () => { + const imageUrl = url.image || url.url; + + if (!imageUrl) return null; + if (imageUrl.includes('http')) return imageUrl; + return `${baseUrl}/${imageUrl}?rc_uid=${user.id}&rc_token=${user.token}`; + }; + const image = getImageUrl(); const onPress = () => openLink(url.url, theme);