From d5c356d54ac9db0c99de3c41b01902cacb7c431a Mon Sep 17 00:00:00 2001 From: Devansh Date: Sun, 22 Dec 2024 12:58:15 +0530 Subject: [PATCH] Added copy link feature --- .../src/views/Message/MessageToolbox.jsx | 7 ++++++ .../src/views/ThemeLab/LayoutSetting.jsx | 6 +++++ packages/react/src/views/Message/Message.js | 23 +++++++++++++++++++ .../react/src/views/Message/MessageToolbox.js | 9 ++++++++ 4 files changed, 45 insertions(+) diff --git a/packages/layout_editor/src/views/Message/MessageToolbox.jsx b/packages/layout_editor/src/views/Message/MessageToolbox.jsx index 0f4f347d5..4f79f82e9 100644 --- a/packages/layout_editor/src/views/Message/MessageToolbox.jsx +++ b/packages/layout_editor/src/views/Message/MessageToolbox.jsx @@ -155,6 +155,13 @@ export const MessageToolbox = ({ variantStyles = {}, ...props }) => { iconName: 'copy', visible: true, }, + link: { + label: 'Copy link', + id: 'copyLink', + onClick: () => {}, + iconName: 'link', + visible: true, + }, delete: { label: 'Delete', id: 'delete', diff --git a/packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx b/packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx index 53d3874e4..b2f98dc62 100644 --- a/packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx +++ b/packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx @@ -364,6 +364,12 @@ const LayoutSetting = () => { }, iconName: 'copy', }, + link: { + label: 'Copy link', + id: 'copyLink', + onClick: () => addMessageSurfaceItem('link'), + iconName: 'link', + }, delete: { label: 'Delete', id: 'delete', diff --git a/packages/react/src/views/Message/Message.js b/packages/react/src/views/Message/Message.js index dceb3eaa3..a17a3c3a3 100644 --- a/packages/react/src/views/Message/Message.js +++ b/packages/react/src/views/Message/Message.js @@ -135,6 +135,28 @@ const Message = ({ }); }; + const getMessageLink = async (id) => { + const host = await RCInstance.getHost(); + const res = await RCInstance.channelInfo(); + return `${host}/channel/${res.room.name}/?msg=${id}`; + }; + + const handleCopyMessageLink = async (msg) => { + try { + const messageLink = await getMessageLink(msg._id); + await navigator.clipboard.writeText(messageLink); + dispatchToastMessage({ + type: 'success', + message: 'Message link copied successfully', + }); + } catch (err) { + dispatchToastMessage({ + type: 'error', + message: 'Error in copying message link', + }); + } + }; + const handleDeleteMessage = async (msg) => { const res = await RCInstance.deleteMessage(msg._id); @@ -233,6 +255,7 @@ const Message = ({ pinRoles={pinRoles} editMessageRoles={editMessageRoles} handleCopyMessage={handleCopyMessage} + handleCopyMessageLink={handleCopyMessageLink} handleOpenThread={handleOpenThread} handleDeleteMessage={handleDeleteMessage} handleStarMessage={handleStarMessage} diff --git a/packages/react/src/views/Message/MessageToolbox.js b/packages/react/src/views/Message/MessageToolbox.js index a15a532f0..405142b69 100644 --- a/packages/react/src/views/Message/MessageToolbox.js +++ b/packages/react/src/views/Message/MessageToolbox.js @@ -31,6 +31,7 @@ export const MessageToolbox = ({ handleDeleteMessage, handlerReportMessage, handleCopyMessage, + handleCopyMessageLink, handleEditMessage, handleQuoteMessage, isEditing = false, @@ -41,6 +42,7 @@ export const MessageToolbox = ({ 'quote', 'star', 'copy', + 'link', 'pin', 'edit', 'delete', @@ -139,6 +141,13 @@ export const MessageToolbox = ({ iconName: 'copy', visible: true, }, + link: { + label: 'Copy link', + id: 'copyLink', + onClick: () => handleCopyMessageLink(message), + iconName: 'link', + visible: true, + }, delete: { label: 'Delete', id: 'delete',