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

Commit b55f69a

Browse files
author
James Salter
authored
Merge pull request #6374 from matrix-org/copy-room
Add "Copy Link" to room context menu
2 parents 5f2fab0 + 767d970 commit b55f69a

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

res/css/views/rooms/_RoomTile.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ limitations under the License.
193193
mask-image: url('$(res)/img/element-icons/settings.svg');
194194
}
195195

196+
.mx_RoomTile_iconCopyLink::before {
197+
mask-image: url('$(res)/img/element-icons/link.svg');
198+
}
199+
196200
.mx_RoomTile_iconInvite::before {
197201
mask-image: url('$(res)/img/element-icons/room/invite.svg');
198202
}

src/components/structures/MatrixChat.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ import VerificationRequestToast from '../views/toasts/VerificationRequestToast';
105105
import PerformanceMonitor, { PerformanceEntryNames } from "../../performance";
106106
import UIStore, { UI_EVENTS } from "../../stores/UIStore";
107107
import SoftLogout from './auth/SoftLogout';
108+
import { makeRoomPermalink } from "../../utils/permalinks/Permalinks";
109+
import { copyPlaintext } from "../../utils/strings";
108110

109111
/** constants for MatrixChat.state.view */
110112
export enum Views {
@@ -627,6 +629,9 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
627629
case 'forget_room':
628630
this.forgetRoom(payload.room_id);
629631
break;
632+
case 'copy_room':
633+
this.copyRoom(payload.room_id);
634+
break;
630635
case 'reject_invite':
631636
Modal.createTrackedDialog('Reject invitation', '', QuestionDialog, {
632637
title: _t('Reject invitation'),
@@ -1193,6 +1198,17 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
11931198
});
11941199
}
11951200

1201+
private async copyRoom(roomId: string) {
1202+
const roomLink = makeRoomPermalink(roomId);
1203+
const success = await copyPlaintext(roomLink);
1204+
if (!success) {
1205+
Modal.createTrackedDialog("Unable to copy room link", "", ErrorDialog, {
1206+
title: _t("Unable to copy room link"),
1207+
description: _t("Unable to copy a link to the room to the clipboard."),
1208+
});
1209+
}
1210+
}
1211+
11961212
/**
11971213
* Starts a chat with the welcome user, if the user doesn't already have one
11981214
* @returns {string} The room ID of the new room, or null if no room was created

src/components/views/rooms/RoomTile.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,17 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
358358
this.setState({ generalMenuPosition: null }); // hide the menu
359359
};
360360

361+
private onCopyRoomClick = (ev: ButtonEvent) => {
362+
ev.preventDefault();
363+
ev.stopPropagation();
364+
365+
dis.dispatch({
366+
action: 'copy_room',
367+
room_id: this.props.room.roomId,
368+
});
369+
this.setState({ generalMenuPosition: null }); // hide the menu
370+
};
371+
361372
private onInviteClick = (ev: ButtonEvent) => {
362373
ev.preventDefault();
363374
ev.stopPropagation();
@@ -517,6 +528,11 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
517528
iconClassName="mx_RoomTile_iconInvite"
518529
/>
519530
) : null}
531+
<IconizedContextMenuOption
532+
onClick={this.onCopyRoomClick}
533+
label={_t("Copy Link")}
534+
iconClassName="mx_RoomTile_iconCopyLink"
535+
/>
520536
<IconizedContextMenuOption
521537
onClick={this.onOpenRoomSettings}
522538
label={_t("Settings")}

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@
16671667
"Favourite": "Favourite",
16681668
"Low Priority": "Low Priority",
16691669
"Invite People": "Invite People",
1670+
"Copy Link": "Copy Link",
16701671
"Leave Room": "Leave Room",
16711672
"Room options": "Room options",
16721673
"%(count)s unread messages including mentions.|other": "%(count)s unread messages including mentions.",
@@ -2674,6 +2675,8 @@
26742675
"Are you sure you want to leave the space '%(spaceName)s'?": "Are you sure you want to leave the space '%(spaceName)s'?",
26752676
"Are you sure you want to leave the room '%(roomName)s'?": "Are you sure you want to leave the room '%(roomName)s'?",
26762677
"Failed to forget room %(errCode)s": "Failed to forget room %(errCode)s",
2678+
"Unable to copy room link": "Unable to copy room link",
2679+
"Unable to copy a link to the room to the clipboard.": "Unable to copy a link to the room to the clipboard.",
26772680
"Signed Out": "Signed Out",
26782681
"For security, this session has been signed out. Please sign in again.": "For security, this session has been signed out. Please sign in again.",
26792682
"Terms and Conditions": "Terms and Conditions",

0 commit comments

Comments
 (0)