diff --git a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx index 2f52ebe42fa9..11a19fb4f36e 100644 --- a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx +++ b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx @@ -11,6 +11,7 @@ import React, { memo, useMemo, useRef } from 'react'; import MessageActionMenu from './MessageActionMenu'; import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu'; import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction'; +import { usePermalinkPinned } from './usePermalinkPinned'; import { useWebDAVMessageAction } from './useWebDAVMessageAction'; import type { MessageActionContext } from '../../../../app/ui-utils/client/lib/MessageAction'; import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction'; @@ -87,6 +88,7 @@ const MessageToolbar = ({ // TODO: move this to another place useWebDAVMessageAction(); useNewDiscussionMessageAction(); + usePermalinkPinned(); const actionsQueryResult = useQuery(['rooms', room._id, 'messages', message._id, 'actions'] as const, async () => { const props = { message, room, user, subscription, settings: mapSettings, chat }; diff --git a/apps/meteor/client/components/message/toolbar/usePermalinkPinned.tsx b/apps/meteor/client/components/message/toolbar/usePermalinkPinned.tsx new file mode 100644 index 000000000000..7ed34c5b5982 --- /dev/null +++ b/apps/meteor/client/components/message/toolbar/usePermalinkPinned.tsx @@ -0,0 +1,43 @@ +import { isE2EEMessage } from '@rocket.chat/core-typings'; +import { useToastMessageDispatch } from '@rocket.chat/ui-contexts'; +import { useEffect } from 'react'; +import { useTranslation } from 'react-i18next'; + +import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction'; +import { getPermaLink } from '../../../lib/getPermaLink'; + +export const usePermalinkPinned = () => { + const { t } = useTranslation(); + + const dispatchToastMessage = useToastMessageDispatch(); + + useEffect(() => { + MessageAction.addButton({ + id: 'permalink-pinned', + icon: 'permalink', + label: 'Copy_link', + context: ['pinned'], + async action(_, { message }) { + try { + const permalink = await getPermaLink(message._id); + navigator.clipboard.writeText(permalink); + dispatchToastMessage({ type: 'success', message: t('Copied') }); + } catch (e) { + dispatchToastMessage({ type: 'error', message: e }); + } + }, + condition({ subscription }) { + return !!subscription; + }, + order: 5, + group: 'menu', + disabled({ message }) { + return isE2EEMessage(message); + }, + }); + + return () => { + MessageAction.removeButton('permalink-pinned'); + }; + }, [dispatchToastMessage, t]); +}; diff --git a/apps/meteor/client/startup/actionButtons/index.ts b/apps/meteor/client/startup/actionButtons/index.ts index 97ccf359d567..b88b57fce013 100644 --- a/apps/meteor/client/startup/actionButtons/index.ts +++ b/apps/meteor/client/startup/actionButtons/index.ts @@ -2,7 +2,6 @@ import './jumpToMessage'; import './jumpToPinMessage'; import './jumpToSearchMessage'; import './jumpToStarMessage'; -import './permalinkPinned'; import './permalinkStar'; import './pinMessage'; import './starMessage'; diff --git a/apps/meteor/client/startup/actionButtons/permalinkPinned.ts b/apps/meteor/client/startup/actionButtons/permalinkPinned.ts deleted file mode 100644 index add09ca7dcd0..000000000000 --- a/apps/meteor/client/startup/actionButtons/permalinkPinned.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { isE2EEMessage } from '@rocket.chat/core-typings'; -import { Meteor } from 'meteor/meteor'; - -import { MessageAction } from '../../../app/ui-utils/client'; -import { t } from '../../../app/utils/lib/i18n'; -import { getPermaLink } from '../../lib/getPermaLink'; -import { dispatchToastMessage } from '../../lib/toast'; - -Meteor.startup(() => { - MessageAction.addButton({ - id: 'permalink-pinned', - icon: 'permalink', - label: 'Copy_link', - context: ['pinned'], - async action(_, { message }) { - try { - const permalink = await getPermaLink(message._id); - navigator.clipboard.writeText(permalink); - dispatchToastMessage({ type: 'success', message: t('Copied') }); - } catch (e) { - dispatchToastMessage({ type: 'error', message: e }); - } - }, - condition({ subscription }) { - return !!subscription; - }, - order: 5, - group: 'menu', - disabled({ message }) { - return isE2EEMessage(message); - }, - }); -});