diff --git a/app/components/markdown/markdown_link/markdown_link.tsx b/app/components/markdown/markdown_link/markdown_link.tsx index 9d471faa8..f36ccd6bb 100644 --- a/app/components/markdown/markdown_link/markdown_link.tsx +++ b/app/components/markdown/markdown_link/markdown_link.tsx @@ -4,7 +4,7 @@ import {useManagedConfig} from '@mattermost/react-native-emm'; import Clipboard from '@react-native-clipboard/clipboard'; import React, {Children, type ReactElement, useCallback} from 'react'; -import {useIntl} from 'react-intl'; +import {useIntl, defineMessages} from 'react-intl'; import {Alert, StyleSheet, Text, View} from 'react-native'; import urlParse from 'url-parse'; @@ -13,7 +13,7 @@ import {useServerUrl} from '@context/server'; import {useTheme} from '@context/theme'; import {bottomSheet, dismissBottomSheet} from '@screens/navigation'; import {handleDeepLink, matchDeepLink} from '@utils/deep_link'; -import {bottomSheetSnapPoint} from '@utils/helpers'; +import {bottomSheetSnapPoint, isEmail} from '@utils/helpers'; import {preventDoubleTap} from '@utils/tap'; import {normalizeProtocol, tryOpenURL} from '@utils/url'; @@ -25,6 +25,17 @@ type MarkdownLinkProps = { onLinkLongPress?: (url?: string) => void; } +const messages = defineMessages({ + copyEmail: { + id: 'mobile.markdown.link.copy_email', + defaultMessage: 'Copy Email Address', + }, + copyURL: { + id: 'mobile.markdown.link.copy_url', + defaultMessage: 'Copy URL', + }, +}); + const style = StyleSheet.create({ bottomSheet: { flex: 1, @@ -113,6 +124,9 @@ const MarkdownLink = ({children, experimentalNormalizeMarkdownLinks, href, siteU return; } + const cleanHref = href.replace(/^mailto:/, ''); + const isEmailLink = isEmail(cleanHref); + const renderContent = () => { return ( { dismissBottomSheet(); - Clipboard.setString(href); + Clipboard.setString(cleanHref); }} testID='at_mention.bottom_sheet.copy_url' - text={intl.formatMessage({id: 'mobile.markdown.link.copy_url', defaultMessage: 'Copy URL'})} + text={intl.formatMessage(isEmailLink ? messages.copyEmail : messages.copyURL)} /> { Clipboard.setString(text); await dismissBottomSheet(); @@ -114,6 +125,10 @@ const Extra = ({channelId, createdAt, createdBy, customStatus, header, isCustomS const handleLongPress = useCallback((url?: string) => { if (managedConfig?.copyAndPasteProtection !== 'true') { + + const cleanUrl = url?.replace(/^mailto:/, '') || ''; + const isEmailLink = isEmail(cleanUrl); + const renderContent = () => ( { - onCopy(url!, true); + onCopy(cleanUrl, true); }} testID={`${headerTestId}.bottom_sheet.copy_url`} - text={intl.formatMessage({ - id: 'mobile.markdown.link.copy_url', - defaultMessage: 'Copy URL', - })} + text={intl.formatMessage(isEmailLink ? messages.copyEmail : messages.copyURL)} /> )}