Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msglist: Catch invalid-URL error on link long-press #5855

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/webview/handleOutboundEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as api from '../api';
import config from '../config';
import type { UserId } from '../types';
import type { JSONableDict } from '../utils/jsonable';
import { showErrorAlert, showToast } from '../utils/info';
import { showConfirmationDialog, showErrorAlert, showToast } from '../utils/info';
import { pmKeyRecipientsFromMessage } from '../utils/recipient';
import { isUrlAnImage, tryParseUrl } from '../utils/url';
import * as logging from '../utils/logging';
Expand Down Expand Up @@ -206,11 +206,26 @@ const handleLongPress = (args: {|
navigation: AppNavigationMethods,
|}) => {
const { props, target, messageId, href, navigation } = args;
const { _ } = props;

if (href !== null) {
const url = new URL(href, props.backgroundData.auth.realm).toString();
Clipboard.setString(url);
const { _ } = props;
const url = tryParseUrl(href, props.backgroundData.auth.realm);
if (url == null) {
showConfirmationDialog({
title: 'Copy invalid link',
message: {
text: 'This link appears to be invalid. Do you want to copy it anyway?\n\n{text}',
values: { text: href },
},
onPressConfirm: () => {
Clipboard.setString(href);
showToast(_('Text copied'));
},
_,
});
return;
}
Clipboard.setString(url.toString());
showToast(_('Link copied'));
return;
}
Expand All @@ -227,7 +242,6 @@ const handleLongPress = (args: {|
startEditMessage,
setDoNotMarkMessagesAsRead,
composeBoxRef,
_,
} = props;
if (target === 'header') {
if (message.type === 'stream') {
Expand Down
3 changes: 3 additions & 0 deletions static/translations/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Copied": "Copied",
"Copy invalid link": "Copy invalid link",
"This link appears to be invalid. Do you want to copy it anyway?\n\n{text}": "This link appears to be invalid. Do you want to copy it anyway?\n\n{text}",
"Text copied": "Text copied",
"Link copied": "Link copied",
"This time is in your timezone. Original text was “{originalText}”.": "This time is in your timezone. Original text was “{originalText}”.",
"Mute topic": "Mute topic",
Expand Down
Loading