From c7d2f306c5649553d7aa33ecd9cba6a88bba0dd5 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Thu, 1 Dec 2022 19:44:44 -0300 Subject: [PATCH] [FIX] Link preview with embed image --- app/containers/message/Urls.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/containers/message/Urls.tsx b/app/containers/message/Urls.tsx index a8863cb85..3503d0b7d 100644 --- a/app/containers/message/Urls.tsx +++ b/app/containers/message/Urls.tsx @@ -94,6 +94,11 @@ const UrlContent = React.memo( } ); +const isImage = (url: string) => { + const regExpUrlImage = new RegExp(/\.(jpg|jpeg|png|webp|avif|gif|svg)$/); + return regExpUrlImage.test(url); +}; + const Url = React.memo( ({ url, index, theme }: { url: IUrl; index: number; theme: TSupportedThemes }) => { if (!url || url?.ignoreParse) { @@ -107,6 +112,14 @@ const Url = React.memo( EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') }); }; + let imageUrl; + + if (url.image) { + imageUrl = url.image; + } else { + imageUrl = isImage(url.url) ? url.url : ''; + } + return ( <> - - + + {url.title || url.description ? : null} );