Protected Messages: Allow copy link action (#3725)

This commit is contained in:
Alexander Zinchuk 2023-08-14 11:17:45 +02:00
parent 5b96a6635f
commit ffafa27106
5 changed files with 22 additions and 9 deletions

View File

@ -585,9 +585,9 @@ const Message: FC<OwnProps & StateProps> = ({
}, [focusLastMessage, isLastInList, transcribedText, withVoiceTranscription]); }, [focusLastMessage, isLastInList, transcribedText, withVoiceTranscription]);
const containerClassName = buildClassName( const containerClassName = buildClassName(
'Message message-list-item allow-selection', 'Message message-list-item',
isFirstInGroup && 'first-in-group', isFirstInGroup && 'first-in-group',
isProtected && 'is-protected', isProtected ? 'is-protected' : 'allow-selection',
isLastInGroup && 'last-in-group', isLastInGroup && 'last-in-group',
isFirstInDocumentGroup && 'first-in-document-group', isFirstInDocumentGroup && 'first-in-document-group',
isLastInDocumentGroup && 'last-in-document-group', isLastInDocumentGroup && 'last-in-document-group',

View File

@ -250,7 +250,13 @@ const MessageContextMenu: FC<OwnProps> = ({
const copyOptions = isSponsoredMessage const copyOptions = isSponsoredMessage
? [] ? []
: getMessageCopyOptions( : getMessageCopyOptions(
message, targetHref, handleAfterCopy, canCopyLink ? onCopyLink : undefined, onCopyMessages, onCopyNumber, message,
targetHref,
canCopy,
handleAfterCopy,
canCopyLink ? onCopyLink : undefined,
onCopyMessages,
onCopyNumber,
); );
const getTriggerElement = useLastCallback(() => { const getTriggerElement = useLastCallback(() => {
@ -372,7 +378,7 @@ const MessageContextMenu: FC<OwnProps> = ({
{canSelectLanguage && ( {canSelectLanguage && (
<MenuItem icon="web" onClick={onSelectLanguage}>{lang('lng_settings_change_lang')}</MenuItem> <MenuItem icon="web" onClick={onSelectLanguage}>{lang('lng_settings_change_lang')}</MenuItem>
)} )}
{canCopy && copyOptions.map((option) => ( {copyOptions.map((option) => (
<MenuItem key={option.label} icon={option.icon} onClick={option.handler}>{lang(option.label)}</MenuItem> <MenuItem key={option.label} icon={option.icon} onClick={option.handler}>{lang(option.label)}</MenuItem>
))} ))}
{canPin && <MenuItem icon="pin" onClick={onPin}>{lang('DialogPin')}</MenuItem>} {canPin && <MenuItem icon="pin" onClick={onPin}>{lang('DialogPin')}</MenuItem>}

View File

@ -30,6 +30,7 @@ type ICopyOptions = {
export function getMessageCopyOptions( export function getMessageCopyOptions(
message: ApiMessage, message: ApiMessage,
href?: string, href?: string,
canCopy?: boolean,
afterEffect?: () => void, afterEffect?: () => void,
onCopyLink?: () => void, onCopyLink?: () => void,
onCopyMessages?: (messageIds: number[]) => void, onCopyMessages?: (messageIds: number[]) => void,
@ -41,7 +42,8 @@ export function getMessageCopyOptions(
|| (!getMessageWebPageVideo(message) ? getMessageWebPagePhoto(message) : undefined); || (!getMessageWebPageVideo(message) ? getMessageWebPagePhoto(message) : undefined);
const contact = getMessageContact(message); const contact = getMessageContact(message);
const mediaHash = getMessageMediaHash(message, 'inline'); const mediaHash = getMessageMediaHash(message, 'inline');
const canImageBeCopied = photo && (mediaHash || hasMessageLocalBlobUrl(message)) && CLIPBOARD_ITEM_SUPPORTED; const canImageBeCopied = canCopy && photo && (mediaHash || hasMessageLocalBlobUrl(message))
&& CLIPBOARD_ITEM_SUPPORTED;
const selection = window.getSelection(); const selection = window.getSelection();
if (canImageBeCopied) { if (canImageBeCopied) {
@ -57,7 +59,7 @@ export function getMessageCopyOptions(
}); });
} }
if (href) { if (canCopy && href) {
options.push({ options.push({
label: 'lng_context_copy_link', label: 'lng_context_copy_link',
icon: 'copy', icon: 'copy',
@ -67,7 +69,7 @@ export function getMessageCopyOptions(
afterEffect?.(); afterEffect?.();
}, },
}); });
} else if (text) { } else if (canCopy && text) {
// Detect if the user has selection in the current message // Detect if the user has selection in the current message
const hasSelection = Boolean(( const hasSelection = Boolean((
selection?.anchorNode?.parentNode selection?.anchorNode?.parentNode

View File

@ -33,14 +33,14 @@ const useContextMenuHandlers = (
const handleBeforeContextMenu = useLastCallback((e: React.MouseEvent) => { const handleBeforeContextMenu = useLastCallback((e: React.MouseEvent) => {
if (!isMenuDisabled && e.button === 2) { if (!isMenuDisabled && e.button === 2) {
requestMutation(() => { requestMutation(() => {
removeExtraClass(e.target as HTMLElement, 'allow-selection'); addExtraClass(e.target as HTMLElement, 'no-selection');
}); });
} }
}); });
const handleContextMenu = useLastCallback((e: React.MouseEvent) => { const handleContextMenu = useLastCallback((e: React.MouseEvent) => {
requestMutation(() => { requestMutation(() => {
addExtraClass(e.target as HTMLElement, 'allow-selection'); removeExtraClass(e.target as HTMLElement, 'no-selection');
}); });
if (isMenuDisabled || (shouldDisableOnLink && (e.target as HTMLElement).matches('a[href]'))) { if (isMenuDisabled || (shouldDisableOnLink && (e.target as HTMLElement).matches('a[href]'))) {

View File

@ -120,6 +120,11 @@ body.cursor-ew-resize {
user-select: text; user-select: text;
} }
.no-selection {
user-select: none !important;
-webkit-user-select: none !important;
}
.clearfix::after { .clearfix::after {
content: ""; content: "";
clear: both; clear: both;