diff --git a/src/components/common/ChatExtra.tsx b/src/components/common/ChatExtra.tsx index 64a02c21a..747ba9aa1 100644 --- a/src/components/common/ChatExtra.tsx +++ b/src/components/common/ChatExtra.tsx @@ -115,6 +115,7 @@ const ChatExtra: FC = ({ }, [peerId, chat, user]); const isTopicInfo = Boolean(topicId && topicId !== MAIN_THREAD_ID); + const shouldRenderAllLinks = (chat && isChatChannel(chat)) || user?.isPremium; const activeUsernames = useMemo(() => { const result = usernames?.filter((u) => u.isActive); @@ -243,7 +244,13 @@ const ChatExtra: FC = ({ isStatic > - {renderText(description, ['br', 'links', 'emoji'])} + { + renderText(description, [ + 'br', + shouldRenderAllLinks ? 'links' : 'tg_links', + 'emoji', + ]) + } {lang(userId ? 'UserBio' : 'Info')} diff --git a/src/components/common/helpers/renderText.tsx b/src/components/common/helpers/renderText.tsx index 21841fda9..bb6d2c267 100644 --- a/src/components/common/helpers/renderText.tsx +++ b/src/components/common/helpers/renderText.tsx @@ -8,6 +8,7 @@ import { } from '../../../config'; import EMOJI_REGEX from '../../../lib/twemojiRegex'; import buildClassName from '../../../util/buildClassName'; +import { isDeepLink } from '../../../util/deepLinkParser'; import { fixNonStandardEmoji, handleEmojiLoad, @@ -22,7 +23,7 @@ import SafeLink from '../SafeLink'; export type TextFilter = ( 'escape_html' | 'hq_emoji' | 'emoji' | 'emoji_html' | 'br' | 'br_html' | 'highlight' | 'links' | - 'simple_markdown' | 'simple_markdown_html' | 'quote' + 'simple_markdown' | 'simple_markdown_html' | 'quote' | 'tg_links' ); const SIMPLE_MARKDOWN_REGEX = /(\*\*|__).+?\1/g; @@ -68,6 +69,9 @@ export default function renderText( case 'links': return addLinks(text); + case 'tg_links': + return addLinks(text, true); + case 'simple_markdown': return replaceSimpleMarkdown(text, 'jsx'); @@ -214,7 +218,7 @@ function addHighlight(textParts: TextPart[], highlight: string | undefined, isQu const RE_LINK = new RegExp(`${RE_LINK_TEMPLATE}|${RE_MENTION_TEMPLATE}`, 'ig'); -function addLinks(textParts: TextPart[]): TextPart[] { +function addLinks(textParts: TextPart[], allowOnlyTgLinks?: boolean): TextPart[] { return textParts.reduce((result, part) => { if (typeof part !== 'string') { result.push(part); @@ -245,9 +249,13 @@ function addLinks(textParts: TextPart[]): TextPart[] { nextLink = nextLink.slice(0, nextLink.length - 1); } - content.push( - , - ); + if (!allowOnlyTgLinks || isDeepLink(nextLink)) { + content.push( + , + ); + } else { + content.push(nextLink); + } } lastIndex = index + nextLink.length; nextLink = links.shift();