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

Add "Copy Link" to room context menu #6374

Merged
merged 11 commits into from
Jul 16, 2021
16 changes: 16 additions & 0 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ import VerificationRequestToast from '../views/toasts/VerificationRequestToast';
import PerformanceMonitor, { PerformanceEntryNames } from "../../performance";
import UIStore, { UI_EVENTS } from "../../stores/UIStore";
import SoftLogout from './auth/SoftLogout';
import { makeRoomPermalink } from "../../utils/permalinks/Permalinks";
import { copyPlaintext } from "../../utils/strings";

/** constants for MatrixChat.state.view */
export enum Views {
Expand Down Expand Up @@ -627,6 +629,9 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
case 'forget_room':
this.forgetRoom(payload.room_id);
break;
case 'copy_room':
this.copyRoom(payload.room_id);
break;
case 'reject_invite':
Modal.createTrackedDialog('Reject invitation', '', QuestionDialog, {
title: _t('Reject invitation'),
Expand Down Expand Up @@ -1193,6 +1198,17 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
});
}

private async copyRoom(roomId: string) {
const roomLink = makeRoomPermalink(roomId);
const success = await copyPlaintext(roomLink);
if (!success) {
Modal.createTrackedDialog("Unable to copy room", "", ErrorDialog, {
title: _t("Unable to copy room"),
description: _t("Unable to copy the room to the clipboard."),
Copy link
Member

@t3chguy t3chguy Jul 16, 2021

Choose a reason for hiding this comment

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

these should probably be room link as otherwise the error might be suggesting that you're copying the entire room to the clipboard, where an error would be way more expected.

});
}
}

/**
* Starts a chat with the welcome user, if the user doesn't already have one
* @returns {string} The room ID of the new room, or null if no room was created
Expand Down
16 changes: 16 additions & 0 deletions src/components/views/rooms/RoomTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
this.setState({ generalMenuPosition: null }); // hide the menu
};

private onCopyRoomClick = (ev: ButtonEvent) => {
ev.preventDefault();
ev.stopPropagation();

dis.dispatch({
action: 'copy_room',
room_id: this.props.room.roomId,
});
this.setState({ generalMenuPosition: null }); // hide the menu
};

private onInviteClick = (ev: ButtonEvent) => {
ev.preventDefault();
ev.stopPropagation();
Expand Down Expand Up @@ -522,6 +533,11 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
label={_t("Settings")}
iconClassName="mx_RoomTile_iconSettings"
/>
<IconizedContextMenuOption
onClick={this.onCopyRoomClick}
label={_t("Copy")}
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
iconClassName="mx_RoomTile_iconSettings"
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
/>
</IconizedContextMenuOptionList>
<IconizedContextMenuOptionList red>
<IconizedContextMenuOption
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2671,6 +2671,8 @@
"Are you sure you want to leave the space '%(spaceName)s'?": "Are you sure you want to leave the space '%(spaceName)s'?",
"Are you sure you want to leave the room '%(roomName)s'?": "Are you sure you want to leave the room '%(roomName)s'?",
"Failed to forget room %(errCode)s": "Failed to forget room %(errCode)s",
"Unable to copy room": "Unable to copy room",
"Unable to copy the room to the clipboard.": "Unable to copy the room to the clipboard.",
"Signed Out": "Signed Out",
"For security, this session has been signed out. Please sign in again.": "For security, this session has been signed out. Please sign in again.",
"Terms and Conditions": "Terms and Conditions",
Expand Down