Skip to content
Closed
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
29 changes: 29 additions & 0 deletions src/message/__tests__/messageActionSheet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,35 @@ describe('constructActionButtons', () => {

expect(buttons).toContain('unstarMessage');
});

test('show copy link option if long pressed on link', () => {
const message = deepFreeze({
id: 1,
});

const buttons = constructMessageActionButtons({
backgroundData: { auth, flags },
message,
narrow,
href: 'https://zulipchat.com',
});

expect(buttons).toContain('copyLinkToClipboard');
});

test('show copy message option if long pressed on a text', () => {
const message = deepFreeze({
id: 1,
});

const buttons = constructMessageActionButtons({
backgroundData: { auth, flags },
message,
narrow,
});

expect(buttons).toContain('copyToClipboard');
});
});

describe('constructHeaderActionButtons', () => {
Expand Down
16 changes: 15 additions & 1 deletion src/message/messageActionSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ButtonDescription = {
message: Message,
subscriptions: Subscription[],
dispatch: Dispatch,
href: string,
_: GetText,
}): void | Promise<void>,
title: string,
Expand All @@ -42,6 +43,12 @@ const copyToClipboard = async ({ _, auth, message }) => {
};
copyToClipboard.title = 'Copy to clipboard';

const copyLinkToClipboard = async ({ _, href }) => {
Clipboard.setString(href);
showToast(_('Link copied'));
};
copyLinkToClipboard.title = 'Copy link to clipboard';

const editMessage = async ({ message, dispatch }) => {
dispatch(startEditMessage(message.id, message.subject));
};
Expand Down Expand Up @@ -112,6 +119,7 @@ const allButtonsRaw = {
addReaction,
reply,
copyToClipboard,
copyLinkToClipboard,
shareMessage,
editMessage,
deleteMessage,
Expand Down Expand Up @@ -140,6 +148,7 @@ type ConstructSheetParams = {|
backgroundData: BackgroundData,
message: Message,
narrow: Narrow,
href: string,
|};

export const constructHeaderActionButtons = ({
Expand Down Expand Up @@ -170,6 +179,7 @@ export const constructMessageActionButtons = ({
backgroundData: { auth, flags },
message,
narrow,
href,
}: ConstructSheetParams): ButtonCode[] => {
const buttons = [];
if (!isAnOutboxMessage(message) && messageNotDeleted(message)) {
Expand All @@ -179,7 +189,11 @@ export const constructMessageActionButtons = ({
buttons.push('reply');
}
if (messageNotDeleted(message)) {
buttons.push('copyToClipboard');
if (href) {
buttons.push('copyLinkToClipboard');
} else {
buttons.push('copyToClipboard');
}
buttons.push('shareMessage');
}
if (
Expand Down
3 changes: 2 additions & 1 deletion src/webview/js/generatedEs3.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ var handleLongPress = function handleLongPress(target) {
sendMessage({
type: 'longPress',
target: target.matches('.header') ? 'header' : 'message',
messageId: getMessageIdFromNode(target)
messageId: getMessageIdFromNode(target),
href: target.matches('a') ? target.getAttribute('href') : ''
});
};

Expand Down
1 change: 1 addition & 0 deletions src/webview/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ const handleLongPress = (target: Element) => {
type: 'longPress',
target: target.matches('.header') ? 'header' : 'message',
messageId: getMessageIdFromNode(target),
href: target.matches('a') ? target.getAttribute('href') : '',
});
};

Expand Down
12 changes: 10 additions & 2 deletions src/webview/webViewEventHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type MessageListEventLongPress = {|
type: 'longPress',
target: 'message' | 'header',
messageId: number,
href: string,
|};

type MessageListEventDebug = {|
Expand Down Expand Up @@ -150,7 +151,13 @@ const handleImage = (props: Props, src: string, messageId: number) => {
}
};

const handleLongPress = (props: Props, _: GetText, isHeader: boolean, messageId: number) => {
const handleLongPress = (
props: Props,
_: GetText,
isHeader: boolean,
messageId: number,
href: string,
) => {
const message = props.messages.find(x => x.id === messageId);
if (!message) {
return;
Expand All @@ -160,6 +167,7 @@ const handleLongPress = (props: Props, _: GetText, isHeader: boolean, messageId:
backgroundData,
message,
narrow,
href,
});
};

Expand Down Expand Up @@ -187,7 +195,7 @@ export const handleMessageListEvent = (props: Props, _: GetText, event: MessageL
break;

case 'longPress':
handleLongPress(props, _, event.target === 'header', event.messageId);
handleLongPress(props, _, event.target === 'header', event.messageId, event.href);
break;

case 'url':
Expand Down
2 changes: 2 additions & 0 deletions static/translations/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Reply": "Reply",
"Add a reaction": "Add a reaction",
"Copy to clipboard": "Copy to clipboard",
"Copy link to clipboard": "Copy link to clipboard",
"Mute topic": "Mute topic",
"Unmute topic": "Unmute topic",
"Mute stream": "Mute stream",
Expand Down Expand Up @@ -118,6 +119,7 @@
"Unstar message": "Unstar message",
"Cancel": "Cancel",
"Message copied": "Message copied",
"Link copied": "Link copied",
"Edit message": "Edit message",
"Network request failed": "Network request failed",
"show": "show",
Expand Down