From 3c0486668220b61759f81ab129b3147d269c2bf6 Mon Sep 17 00:00:00 2001 From: 1aerostorm Date: Fri, 10 Nov 2023 07:41:42 +0000 Subject: [PATCH] Fix links in Memo --- app/components/App.jsx | 2 +- app/components/elements/Memo.jsx | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/components/App.jsx b/app/components/App.jsx index 6fece5d..f28eded 100644 --- a/app/components/App.jsx +++ b/app/components/App.jsx @@ -38,7 +38,7 @@ const GlobalStyle = createGlobalStyle` } `; -const availableDomains = [ +export const availableDomains = [ 'golos.id', 'golos.in', 'golos.today', diff --git a/app/components/elements/Memo.jsx b/app/components/elements/Memo.jsx index db8d34e..2d4446e 100644 --- a/app/components/elements/Memo.jsx +++ b/app/components/elements/Memo.jsx @@ -5,6 +5,7 @@ import tt from 'counterpart'; import { memo, } from 'golos-lib-js'; import { Link, } from 'react-router'; +import { availableDomains } from 'app/components/App' import links from 'app/utils/Links' import shouldComponentUpdate from 'app/utils/shouldComponentUpdate' import { validate_account_name, } from 'app/utils/ChainValidation' @@ -52,7 +53,7 @@ class Memo extends React.Component { for (let section of text.split(' ')) { if (section.trim().length === 0) continue const matchUserName = section.match(/(^|\s)(@[a-z][-\.a-z\d]+[a-z\d])/i) - const matchLink = section.match(links.local) + let insertPlain = true if (matchUserName) { const user2 = matchUserName[0].trim().substring(1) const userLower = user2.toLowerCase() @@ -60,11 +61,20 @@ class Memo extends React.Component { valid ? sections.push({`@${user2}`} ) : sections.push({`@${user2}`}) + insertPlain = false + } else if (section.match(links.any)) { + let hostname + try { + hostname = new URL(section.trim()).hostname + } catch (err) { + console.error(err) + } + if (availableDomains.includes(hostname)) { + sections.push({section} ) + insertPlain = false + } } - else if (matchLink) { - sections.push({section} ) - } - else { + if (insertPlain) { sections.push({section} ) } }