From 8bf5e61acc72168a9f61a356806949c3af212ae8 Mon Sep 17 00:00:00 2001 From: James Salter Date: Wed, 14 Jul 2021 14:58:18 +0100 Subject: [PATCH 01/10] Add "Copy" to room context menu. This menu item creates a matrix.to link for the room and copies it to the clipboard. --- src/components/structures/MatrixChat.tsx | 16 ++++++++++++++++ src/components/views/rooms/RoomTile.tsx | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index d692b0fa7f..02558a3838 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -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 { @@ -627,6 +629,9 @@ export default class MatrixChat extends React.PureComponent { 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'), @@ -1193,6 +1198,17 @@ export default class MatrixChat extends React.PureComponent { }); } + 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 room"), + }); + } + } + /** * 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 diff --git a/src/components/views/rooms/RoomTile.tsx b/src/components/views/rooms/RoomTile.tsx index 9be0274dd5..8fb4d04791 100644 --- a/src/components/views/rooms/RoomTile.tsx +++ b/src/components/views/rooms/RoomTile.tsx @@ -358,6 +358,17 @@ export default class RoomTile extends React.PureComponent { 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(); @@ -522,6 +533,11 @@ export default class RoomTile extends React.PureComponent { label={_t("Settings")} iconClassName="mx_RoomTile_iconSettings" /> + Date: Wed, 14 Jul 2021 15:02:59 +0100 Subject: [PATCH 02/10] Add English i18n string --- src/i18n/strings/en_EN.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index ced24e2547..ea52d779c3 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -3043,5 +3043,6 @@ "Enter": "Enter", "Space": "Space", "End": "End", - "[number]": "[number]" + "[number]": "[number]", + "Unable to copy room": "Unable to copy room" } From 2fe5ad5d4b5cf36d80ac26c1b323606d8ce808d4 Mon Sep 17 00:00:00 2001 From: James Salter Date: Wed, 14 Jul 2021 15:07:22 +0100 Subject: [PATCH 03/10] Slightly refine error message --- src/components/structures/MatrixChat.tsx | 2 +- src/i18n/strings/en_EN.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 02558a3838..cadf66d11e 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -1204,7 +1204,7 @@ export default class MatrixChat extends React.PureComponent { if (!success) { Modal.createTrackedDialog("Unable to copy room", "", ErrorDialog, { title: _t("Unable to copy room"), - description: _t("Unable to copy room"), + description: _t("Unable to copy the room to the clipboard."), }); } } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index ea52d779c3..03801a9899 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -3044,5 +3044,6 @@ "Space": "Space", "End": "End", "[number]": "[number]", - "Unable to copy room": "Unable to copy room" + "Unable to copy room": "Unable to copy room", + "Unable to copy the room to the clipboard.": "Unable to copy the room to the clipboard." } From e054af7f38d3f60eb7cd62acc0a31ccaa93f947c Mon Sep 17 00:00:00 2001 From: James Salter Date: Wed, 14 Jul 2021 15:35:57 +0100 Subject: [PATCH 04/10] Run yarn i18n --- src/i18n/strings/en_EN.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 03801a9899..d82d19fe3d 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -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", @@ -3043,7 +3045,5 @@ "Enter": "Enter", "Space": "Space", "End": "End", - "[number]": "[number]", - "Unable to copy room": "Unable to copy room", - "Unable to copy the room to the clipboard.": "Unable to copy the room to the clipboard." + "[number]": "[number]" } From 7464900f95976447fbd66b45b5d6814d7ee7675c Mon Sep 17 00:00:00 2001 From: James Salter Date: Fri, 16 Jul 2021 09:05:01 +0100 Subject: [PATCH 05/10] Change menu label to Copy Link --- src/components/views/rooms/RoomTile.tsx | 2 +- src/i18n/strings/en_EN.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomTile.tsx b/src/components/views/rooms/RoomTile.tsx index 8fb4d04791..aa56412149 100644 --- a/src/components/views/rooms/RoomTile.tsx +++ b/src/components/views/rooms/RoomTile.tsx @@ -535,7 +535,7 @@ export default class RoomTile extends React.PureComponent { /> diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index d82d19fe3d..41839a1b2a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1665,6 +1665,7 @@ "Favourite": "Favourite", "Low Priority": "Low Priority", "Invite People": "Invite People", + "Copy Link": "Copy Link", "Leave Room": "Leave Room", "Room options": "Room options", "%(count)s unread messages including mentions.|other": "%(count)s unread messages including mentions.", From a1c658f187830c1105b62be4a6ec29e8b5474203 Mon Sep 17 00:00:00 2001 From: James Salter Date: Fri, 16 Jul 2021 09:07:52 +0100 Subject: [PATCH 06/10] Set Menu icon to link --- res/css/views/rooms/_RoomTile.scss | 4 ++++ src/components/views/rooms/RoomTile.tsx | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/res/css/views/rooms/_RoomTile.scss b/res/css/views/rooms/_RoomTile.scss index 03146e0325..b8f4aeb6e7 100644 --- a/res/css/views/rooms/_RoomTile.scss +++ b/res/css/views/rooms/_RoomTile.scss @@ -193,6 +193,10 @@ limitations under the License. mask-image: url('$(res)/img/element-icons/settings.svg'); } + .mx_RoomTile_iconCopyLink::before { + mask-image: url('$(res)/img/element-icons/link.svg'); + } + .mx_RoomTile_iconInvite::before { mask-image: url('$(res)/img/element-icons/room/invite.svg'); } diff --git a/src/components/views/rooms/RoomTile.tsx b/src/components/views/rooms/RoomTile.tsx index aa56412149..2417b4c6f3 100644 --- a/src/components/views/rooms/RoomTile.tsx +++ b/src/components/views/rooms/RoomTile.tsx @@ -536,7 +536,7 @@ export default class RoomTile extends React.PureComponent { From ff80bbc4a5a862de25b5b1f4eeb7e51d8cf657e3 Mon Sep 17 00:00:00 2001 From: James Salter Date: Fri, 16 Jul 2021 09:10:20 +0100 Subject: [PATCH 07/10] Move copy link to be before settings --- src/components/views/rooms/RoomTile.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/RoomTile.tsx b/src/components/views/rooms/RoomTile.tsx index 2417b4c6f3..aade665b6b 100644 --- a/src/components/views/rooms/RoomTile.tsx +++ b/src/components/views/rooms/RoomTile.tsx @@ -528,16 +528,16 @@ export default class RoomTile extends React.PureComponent { iconClassName="mx_RoomTile_iconInvite" /> ) : null} - + Date: Fri, 16 Jul 2021 09:22:17 +0100 Subject: [PATCH 08/10] Update src/components/views/rooms/RoomTile.tsx Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/rooms/RoomTile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomTile.tsx b/src/components/views/rooms/RoomTile.tsx index aade665b6b..b1c9ed4d98 100644 --- a/src/components/views/rooms/RoomTile.tsx +++ b/src/components/views/rooms/RoomTile.tsx @@ -537,7 +537,7 @@ export default class RoomTile extends React.PureComponent { onClick={this.onOpenRoomSettings} label={_t("Settings")} iconClassName="mx_RoomTile_iconSettings" - /> + /> Date: Fri, 16 Jul 2021 09:24:14 +0100 Subject: [PATCH 09/10] Make error message consistent with menu title --- src/components/structures/MatrixChat.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index cadf66d11e..c6ca965934 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -1202,9 +1202,9 @@ export default class MatrixChat extends React.PureComponent { 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."), + Modal.createTrackedDialog("Unable to copy room link", "", ErrorDialog, { + title: _t("Unable to copy room link"), + description: _t("Unable to copy a link to the room to the clipboard."), }); } } From 767d97065d1367bd96c379b001e0d4a6547d0c38 Mon Sep 17 00:00:00 2001 From: James Salter Date: Fri, 16 Jul 2021 09:36:59 +0100 Subject: [PATCH 10/10] Run i18n --- src/i18n/strings/en_EN.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index edbb7719eb..abdb8c2fb2 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2675,8 +2675,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.", + "Unable to copy room link": "Unable to copy room link", + "Unable to copy a link to the room to the clipboard.": "Unable to copy a link to 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",