Profile Info: Make clickable only telegram links in group description (#4310)
This commit is contained in:
parent
90e6470eed
commit
aea5598e55
@ -115,6 +115,7 @@ const ChatExtra: FC<OwnProps & StateProps> = ({
|
|||||||
}, [peerId, chat, user]);
|
}, [peerId, chat, user]);
|
||||||
|
|
||||||
const isTopicInfo = Boolean(topicId && topicId !== MAIN_THREAD_ID);
|
const isTopicInfo = Boolean(topicId && topicId !== MAIN_THREAD_ID);
|
||||||
|
const shouldRenderAllLinks = (chat && isChatChannel(chat)) || user?.isPremium;
|
||||||
|
|
||||||
const activeUsernames = useMemo(() => {
|
const activeUsernames = useMemo(() => {
|
||||||
const result = usernames?.filter((u) => u.isActive);
|
const result = usernames?.filter((u) => u.isActive);
|
||||||
@ -243,7 +244,13 @@ const ChatExtra: FC<OwnProps & StateProps> = ({
|
|||||||
isStatic
|
isStatic
|
||||||
>
|
>
|
||||||
<span className="title word-break allow-selection" dir="auto">
|
<span className="title word-break allow-selection" dir="auto">
|
||||||
{renderText(description, ['br', 'links', 'emoji'])}
|
{
|
||||||
|
renderText(description, [
|
||||||
|
'br',
|
||||||
|
shouldRenderAllLinks ? 'links' : 'tg_links',
|
||||||
|
'emoji',
|
||||||
|
])
|
||||||
|
}
|
||||||
</span>
|
</span>
|
||||||
<span className="subtitle">{lang(userId ? 'UserBio' : 'Info')}</span>
|
<span className="subtitle">{lang(userId ? 'UserBio' : 'Info')}</span>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import {
|
|||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import EMOJI_REGEX from '../../../lib/twemojiRegex';
|
import EMOJI_REGEX from '../../../lib/twemojiRegex';
|
||||||
import buildClassName from '../../../util/buildClassName';
|
import buildClassName from '../../../util/buildClassName';
|
||||||
|
import { isDeepLink } from '../../../util/deepLinkParser';
|
||||||
import {
|
import {
|
||||||
fixNonStandardEmoji,
|
fixNonStandardEmoji,
|
||||||
handleEmojiLoad,
|
handleEmojiLoad,
|
||||||
@ -22,7 +23,7 @@ import SafeLink from '../SafeLink';
|
|||||||
|
|
||||||
export type TextFilter = (
|
export type TextFilter = (
|
||||||
'escape_html' | 'hq_emoji' | 'emoji' | 'emoji_html' | 'br' | 'br_html' | 'highlight' | 'links' |
|
'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;
|
const SIMPLE_MARKDOWN_REGEX = /(\*\*|__).+?\1/g;
|
||||||
@ -68,6 +69,9 @@ export default function renderText(
|
|||||||
case 'links':
|
case 'links':
|
||||||
return addLinks(text);
|
return addLinks(text);
|
||||||
|
|
||||||
|
case 'tg_links':
|
||||||
|
return addLinks(text, true);
|
||||||
|
|
||||||
case 'simple_markdown':
|
case 'simple_markdown':
|
||||||
return replaceSimpleMarkdown(text, 'jsx');
|
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');
|
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<TextPart[]>((result, part) => {
|
return textParts.reduce<TextPart[]>((result, part) => {
|
||||||
if (typeof part !== 'string') {
|
if (typeof part !== 'string') {
|
||||||
result.push(part);
|
result.push(part);
|
||||||
@ -245,9 +249,13 @@ function addLinks(textParts: TextPart[]): TextPart[] {
|
|||||||
nextLink = nextLink.slice(0, nextLink.length - 1);
|
nextLink = nextLink.slice(0, nextLink.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
content.push(
|
if (!allowOnlyTgLinks || isDeepLink(nextLink)) {
|
||||||
<SafeLink text={nextLink} url={nextLink} />,
|
content.push(
|
||||||
);
|
<SafeLink text={nextLink} url={nextLink} />,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
content.push(nextLink);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lastIndex = index + nextLink.length;
|
lastIndex = index + nextLink.length;
|
||||||
nextLink = links.shift();
|
nextLink = links.shift();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user