Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add Copy Message Contents option in Context Menu #3756

Closed
wants to merge 1 commit into from
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
20 changes: 20 additions & 0 deletions src/components/views/context_menus/MessageContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ module.exports = createReactClass({
this.closeMenu();
},

onCopyClick: function(e: Event) {
const textField = document.createElement('textarea');
textField.innerText = this.props.mxEvent.event.content.body;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event body does not have to match what is rendered due to the html portion of events so this could easily be abused to make people copy-paste things they didn't know they were.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stumbled on this, thinking out loud: This just implies there's no way to use body safely. If a client doesn't support rendering formatted_body, then it will just use body, but then it might show its users something entirely different from what users of clients which do support formatted_body will see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet clients do, EW/ED will use body for desktop notifications for example.

document.body.appendChild(textField);
textField.select();
document.execCommand('copy');
textField.remove();
this.closeMenu();
},

onPermalinkClick: function(e: Event) {
e.preventDefault();
const ShareDialog = sdk.getComponent("dialogs.ShareDialog");
Expand Down Expand Up @@ -314,6 +324,7 @@ module.exports = createReactClass({
let unhidePreviewButton;
let externalURLButton;
let quoteButton;
let copyButton;
let collapseReplyThread;

// status is SENT before remote-echo, null after
Expand Down Expand Up @@ -430,6 +441,14 @@ module.exports = createReactClass({
);
}

if (this.props.eventTileOps && this.props.eventTileOps.getInnerText) {
copyButton = (
<MenuItem className="mx_MessageContextMenu_field" onClick={this.onCopyClick}>
{ _t('Copy Message Contents') }
</MenuItem>
);
}

// Bridges can provide a 'external_url' to link back to the source.
if (
typeof(mxEvent.event.content.external_url) === "string" &&
Expand Down Expand Up @@ -491,6 +510,7 @@ module.exports = createReactClass({
{ unhidePreviewButton }
{ permalinkButton }
{ quoteButton }
{ copyButton }
{ externalURLButton }
{ collapseReplyThread }
{ e2eInfo }
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/strings/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -746,5 +746,6 @@
"Failed to start chat": "Failed to start chat",
"Messages": "Messages",
"Actions": "Actions",
"Other": "Other"
"Other": "Other",
"Copy Message Contents": "Copy Message Contents"
}