From 924a06bee70126e9b2a8bbfc7b66ebc29968a4bf Mon Sep 17 00:00:00 2001 From: Martin Schoeler Date: Thu, 5 Dec 2024 13:55:04 -0300 Subject: [PATCH] chore: remove meteor.startup from permalink-pinned (#34023) Co-authored-by: Tasso Evangelista <2263066+tassoevan@users.noreply.github.com> --- .../client/lib/messageActionDefault.ts | 26 --------------- .../message/toolbar/MessageToolbar.tsx | 12 +++++-- ...ermalinkStar.tsx => usePermalinkAction.ts} | 28 +++++++++------- .../client/startup/actionButtons/index.ts | 1 - .../startup/actionButtons/permalinkPinned.ts | 33 ------------------- apps/meteor/client/startup/index.ts | 1 - 6 files changed, 26 insertions(+), 75 deletions(-) rename apps/meteor/client/components/message/toolbar/{usePermalinkStar.tsx => usePermalinkAction.ts} (62%) delete mode 100644 apps/meteor/client/startup/actionButtons/index.ts delete mode 100644 apps/meteor/client/startup/actionButtons/permalinkPinned.ts diff --git a/apps/meteor/app/ui-utils/client/lib/messageActionDefault.ts b/apps/meteor/app/ui-utils/client/lib/messageActionDefault.ts index 460ac2941e82..1301863b7e53 100644 --- a/apps/meteor/app/ui-utils/client/lib/messageActionDefault.ts +++ b/apps/meteor/app/ui-utils/client/lib/messageActionDefault.ts @@ -118,32 +118,6 @@ Meteor.startup(async () => { group: 'message', }); - MessageAction.addButton({ - id: 'permalink', - icon: 'permalink', - label: 'Copy_link', - // classes: 'clipboard', - context: ['message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'], - type: 'duplication', - async action(_, { message }) { - try { - const permalink = await getPermaLink(message._id); - await 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); - }, - }); - MessageAction.addButton({ id: 'copy', icon: 'copy', diff --git a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx index 464cb51bc175..53ae98d5bcf8 100644 --- a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx +++ b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx @@ -13,7 +13,7 @@ import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu'; import { useFollowMessageAction } from './useFollowMessageAction'; import { useJumpToMessageContextAction } from './useJumpToMessageContextAction'; import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction'; -import { usePermalinkStar } from './usePermalinkStar'; +import { usePermalinkAction } from './usePermalinkAction'; import { usePinMessageAction } from './usePinMessageAction'; import { useReplyInThreadMessageAction } from './useReplyInThreadMessageAction'; import { useStarMessageAction } from './useStarMessageAction'; @@ -102,7 +102,15 @@ const MessageToolbar = ({ usePinMessageAction(message, { room, subscription }); useStarMessageAction(message, { room, user }); useUnstarMessageAction(message, { room, user }); - usePermalinkStar(message, { subscription, user }); + usePermalinkAction(message, { subscription, id: 'permalink-star', context: ['starred'], order: 10 }); + usePermalinkAction(message, { subscription, id: 'permalink-pinned', context: ['pinned'], order: 5 }); + usePermalinkAction(message, { + subscription, + id: 'permalink', + context: ['message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'], + type: 'duplication', + order: 5, + }); useFollowMessageAction(message, { room, user, context }); useUnFollowMessageAction(message, { room, user, context }); useReplyInThreadMessageAction(message, { room, subscription }); diff --git a/apps/meteor/client/components/message/toolbar/usePermalinkStar.tsx b/apps/meteor/client/components/message/toolbar/usePermalinkAction.ts similarity index 62% rename from apps/meteor/client/components/message/toolbar/usePermalinkStar.tsx rename to apps/meteor/client/components/message/toolbar/usePermalinkAction.ts index 15e6cc5056a7..78a197d5c5d7 100644 --- a/apps/meteor/client/components/message/toolbar/usePermalinkStar.tsx +++ b/apps/meteor/client/components/message/toolbar/usePermalinkAction.ts @@ -1,15 +1,22 @@ -import type { IMessage, ISubscription, IUser } from '@rocket.chat/core-typings'; +import type { IMessage, ISubscription } from '@rocket.chat/core-typings'; import { isE2EEMessage } from '@rocket.chat/core-typings'; import { useToastMessageDispatch } from '@rocket.chat/ui-contexts'; import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; +import type { MessageActionConfig, MessageActionContext } from '../../../../app/ui-utils/client/lib/MessageAction'; import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction'; import { getPermaLink } from '../../../lib/getPermaLink'; -export const usePermalinkStar = ( +export const usePermalinkAction = ( message: IMessage, - { user, subscription }: { user: IUser | undefined; subscription: ISubscription | undefined }, + { + subscription, + id, + context, + type, + order, + }: { subscription: ISubscription | undefined; context: MessageActionContext[]; order: number } & Pick, ) => { const { t } = useTranslation(); @@ -18,15 +25,12 @@ export const usePermalinkStar = ( const encrypted = isE2EEMessage(message); useEffect(() => { - if (!subscription) { - return; - } - MessageAction.addButton({ - id: 'permalink-star', + id, icon: 'permalink', label: 'Copy_link', - context: ['starred'], + context, + type, async action() { try { const permalink = await getPermaLink(message._id); @@ -36,13 +40,13 @@ export const usePermalinkStar = ( dispatchToastMessage({ type: 'error', message: e }); } }, - order: 10, + order, group: 'menu', disabled: () => encrypted, }); return () => { - MessageAction.removeButton('permalink-star'); + MessageAction.removeButton(id); }; - }, [dispatchToastMessage, encrypted, message._id, message.starred, subscription, t, user?._id]); + }, [context, dispatchToastMessage, encrypted, id, message._id, order, subscription, t, type]); }; diff --git a/apps/meteor/client/startup/actionButtons/index.ts b/apps/meteor/client/startup/actionButtons/index.ts deleted file mode 100644 index d1e6724638c6..000000000000 --- a/apps/meteor/client/startup/actionButtons/index.ts +++ /dev/null @@ -1 +0,0 @@ -import './permalinkPinned'; 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); - }, - }); -}); diff --git a/apps/meteor/client/startup/index.ts b/apps/meteor/client/startup/index.ts index 569b11bf1c18..3edff17dc427 100644 --- a/apps/meteor/client/startup/index.ts +++ b/apps/meteor/client/startup/index.ts @@ -1,6 +1,5 @@ import '../lib/rooms/roomTypes'; import './absoluteUrl'; -import './actionButtons'; import './afterLogoutCleanUp'; import './appRoot'; import './audit';